我在Mac OS上运行Vagrant 1.8.1和1.8.4。
我已经开始在stream浪汉上使用2台Ubuntu机器:
itais-MacBook-Pro:ansible-dir itaiganot$ ./dev/hosts --list | jq '.' { "web": [ "web" ], "app": [ "app-1" ], "vagrant": [ "web", "app-1" ], "_meta": { "hostvars": { "web": { "ansible_ssh_host": "127.0.0.1", "ansible_ssh_port": "2201", "ansible_ssh_user": "vagrant", "ansible_ssh_private_key_file": "/Users/itaiganot/ansible-dir/.vagrant/machines/web/virtualbox/private_key" }, "app-1": { "ansible_ssh_host": "127.0.0.1", "ansible_ssh_port": "2202", "ansible_ssh_user": "vagrant", "ansible_ssh_private_key_file": "/Users/itaiganot/ansible-dir/.vagrant/machines/app-1/virtualbox/private_key" } } } }
在VagrantFile所在的当前目录中有一个ansible.cfg文件。
itais-MacBook-Pro:ansible-dir itaiganot$ cat ansible.cfg [defaults] host_key_checking = False inventory = dev
在dev目录中有两个文件:hosts – 这是一个python脚本,它可以自动find引导的stream浪机器的IP地址,以及另一个包含angular色configuration的文件:
itais-MacBook-Pro:dev itaiganot$ cat static [web] [app] [role_web:children] web [role_app:children] app
我试图运行以下命令: ansible role_app -a 'hostname'
但我收到以下错误:
ERROR: Unable to find an inventory file, specify one with -i ?
我GOOGLE了,发现我可以导出一个variables指向configuration,如下所示:
export ANSIBLE_CONFIG=/Users/itaiganot/ansible-dir/ansible.cfg
但是这对我也没有帮助。
顺便说一下,将dev目录作为库存添加到命令中:
itais-MacBook-Pro:ansible-dir itaiganot$ ansible role_app -a 'hostname' -i dev app-1 | success | rc=0 >> app-1
任何想法为什么ansible.cfg文件被忽略?
根据Ansible doc: http ://docs.ansible.com/ansible/intro_configuration.html#inventory,这个variables在版本1.9之前是不可用的:
库存
这是Ansible将用来确定哪些主机可以与之通话的库存文件,脚本或目录的默认位置:
inventory = /etc/ansible/hosts它曾经在1.9之前的
hostfile中被称为hostfile
另一件事是确保系统中没有另一个ansible.cfg文件可用: http ://docs.ansible.com/ansible/intro_configuration.html
可以在configuration文件中进行更改和使用,configuration文件将按以下顺序进行处理:
- ANSIBLE_CONFIG(一个环境variables)
- ansible.cfg(在当前目录中)
- .ansible.cfg(在主目录中)
- /etc/ansible/ansible.cfg