simple ansible命令符合"错误:文件主机标记为可执行"

Lar*_*Cai 6 ansible

新的回答.

我使用ppa安装在ubuntu vm 14.04.1版本中安装了ansible

user@ubuntu:~$ ansible --version
ansible 1.7
Run Code Online (Sandbox Code Playgroud)

并且只创建了hosts文件localhost

user@ubuntu:~$ cat hosts
localhost
Run Code Online (Sandbox Code Playgroud)

当我尝试运行这个简单的命令

user@ubuntu:~$ ansible -i hosts all -m ping --ask-pass
SSH password:
ERROR: The file hosts 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`.
Run Code Online (Sandbox Code Playgroud)

更新当我按照指令删除hosts文件的执行模式时,它工作.

但是这条消息对我来说仍然很奇怪,为什么需要执行hosts文件.

这有什么问题?

jar*_*arv 9

可以使用该-i选项将几种类型的文件传递给ansible .

  1. 库存文件 - 单个ini格式库存文件
  2. 动态库存作为json 返回的脚本
  3. 包含(1)和(2)组合的目录

在你的情况下,Ansible假设因为你在文件主机上设置了可执行位,它是一个动态库存可执行文件.

在需要发现要使用的主机的IP地址的情况下,使用动态库存文件(2)是很常见的.例如,您需要查询某种目录服务或API,以获取即时分组的主机列表.