Mac-Osx
Ansible 忽略了它的配置文件(ansible.cfg),可能是什麼原因?
我在 Mac OS 上執行 Vagrant 1.8.1 和 ansible 1.8.4。
我已經在 vagrant 上啟動了 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" } } } }
我
ansible.cfg
在 VagrantFile 所在的目前目錄中有一個文件。itais-MacBook-Pro:ansible-dir itaiganot$ cat ansible.cfg [defaults] host_key_checking = False inventory = dev
在 dev 目錄中有兩個文件: hosts - 這是一個 python 腳本,它會自動查找已啟動的 vagrant 機器的 IP,另一個文件包含角色配置:
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搜尋了它,發現我可以導出一個變數來指向配置,如下所示:
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忽略了嗎?
根據 Ansible 文件:http ://docs.ansible.com/ansible/intro_configuration.html#inventory ,此變數在 1.9 版之前不可用:
存貨
這是清單文件、腳本或目錄的預設位置,Ansible 將使用它來確定它可以與哪些主機通信:
inventory = /etc/ansible/hosts
它曾經
hostfile
在 1.9 之前在 Ansible中被呼叫另一件事是確保系統中沒有另一個可用的 ansible.cfg 文件:http: //docs.ansible.com/ansible/intro_configuration.html
可以在配置文件中進行更改和使用,該配置文件將按以下順序處理:
- ANSIBLE_CONFIG(環境變數)
- ansible.cfg(在目前目錄中)
- .ansible.cfg(在主目錄中)
- /etc/ansible/ansible.cfg