无法使用库存清单文件,因为它是可执行文件 [英] Can't use ansible inventory file because it is executable

查看:147
本文介绍了无法使用库存清单文件,因为它是可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行Ansible库存文件ansible -i hosts-prod all -u root -m ping,但出现此消息失败:

I am trying to run an Ansible inventory file ansible -i hosts-prod all -u root -m ping and it is failing with this message:

ERROR: The file hosts-prod is marked as executable, 
but failed to execute correctly. If this is not supposed 
to be an executable script, correct this with 
`chmod -x hosts-prod`.

我相信这是因为我使用的是Virtual Box和共享文件夹,这迫使我所有文件都改为ug + rwx.而且vbox不允许更改共享文件夹的权限(至少我是Windows共享文件夹)

I believe this is because I am using Virtual Box and shared folders which is forcing all my files to ug+rwx. And vbox does not permit changing permissions on shared folders (at least shared folders coming from Windows which is my situation)

有没有办法允许Ansible运行此文件?我可以看到几个选项:

Is there a way to allow Ansible to run this file? I can see several options:

  1. 编辑hosts-prod成为可执行文件.我不知道这涉及到什么(显然是Ansible的新手.)
  2. 在Ansible中设置一个配置选项,告诉它不要将此文件作为可执行文件运行-只需将其视为静态配置文件即可.我找不到执行此操作的选项,所以我怀疑这是不可能的.
  3. 将文件移动到共享文件夹之外:对于我而言,这不是一个选择.
  4. 您的好主意.
  1. Edit hosts-prod to become an executable file. I don't know what's involved in this (being new to Ansible, obviously).
  2. Set a configuration option in Ansible to tell it not to run this file as executable - just treat it as the static configuration file it is. I can't find an option to do this, so I suspect it's not possible.
  3. Move the file outside of shared-folders: not an option in my case.
  4. Your better idea..

感谢所有帮助/想法!

实际的hosts-prod配置文件如下所示,因此欢迎对其内部可执行的任何提示:

The actual hosts-prod config file looks as follows, so any tips on making it internally executable would be welcome:

web01 ansible_ssh_host=web01.example.com
db01 ansible_ssh_host=db01.example.com

[webservers]
web01

[dbservers]
db01

[all:vars]
ansible_ssh_user=root

推荐答案

可执行清单被解析为JSON而不是ini文件,因此您可以将其转换为输出JSON的脚本.最重要的是,Ansible将一些参数传递给它们只是一个简单的"cat"是不够的:

Executable inventories are parsed as JSON instead of ini files, so you can convert it to a script that outputs JSON. On top of that, Ansible passes some arguments to them to a simple 'cat' isn't enough:

#!/bin/bash
cat <<EOF
{
 "_meta": {
   "hostvars": {
     "host1": { "some_var": "value" }
   }
 },
 "hostgroup1": [
   "host1",
   "host2"
 ]
 ...
}
EOF

不如简单的猫"那么优雅,但应该可以.

Not as elegant as a simple 'cat', but should work.

这篇关于无法使用库存清单文件,因为它是可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆