2017-03-05 62 views
0

我剛開始用Ansible及以下Ansible:錯誤:無效的INI項

[email protected]:~/ex2$ cat prod_inventory 
web1 192.168.33.20 
db1 192.168.33.30 
[webserver] 
web1 

[dbserver] 
db1 

[all:children] 
webserver 
dbserver 

[all:vars] 
ansible_ssh_user=vagrant 
ansible_ssh_pass=vagrant 

我收到以下錯誤提到在使用ping命令模塊

[email protected]:~/ex2$ ansible all -i prod_inventory -m ping 
ERROR: Invalid ini entry: 192.168.33.20 - need more than 1 value to unpack 
[email protected]:~/ex2$ 

不寫一個小盤點後得到我在這裏想念的東西。

請幫

回答

1

庫存文件的前兩行是不正確的:

web1 192.168.33.20 
db1 192.168.33.30 

如果您想將IP地址分配給主機,您需要使用正確的語法來做到這一點:

[webserver] 
web1 ansible_host=192.168.33.20 

[dbserver] 
db1 ansible_host=192.168.33.30 

首先閱讀the documentation然後再隨機嘗試。明確指出:

Suppose you have just static IPs and want to set up some aliases that live in your host file, or you are connecting through tunnels. You can also describe hosts like this:

jumper ansible_port=5555 ansible_host=192.0.2.50 
+0

是的,你說得對,我在筆記上寫錯了。感謝你的回答。 –

1

您錯過了key = value的庫存格式。

web1 ansible_host=192.168.33.20 
db1 ansible_host=192.168.33.30 
[webserver] 
web1 

[dbserver] 
db1 

[all:children] 
webserver 
dbserver 

[all:vars] 
ansible_ssh_user=vagrant 
ansible_ssh_pass=vagrant 
+0

不能接受已回答,但感謝您的時間 –

-1

Ansible 2.0棄用sshansible_ssh_useransible_ssh_host,和ansible_ssh_port成爲ansible_useransible_host,並ansible_port。如果您使用2.0版之前的Ansible版本,則應繼續使用舊版變量(ansible_ssh_*)。在較早版本的Ansible中,這些較短的變量會被忽略,而不會發出警告。

http://docs.ansible.com/ansible/latest/intro_inventory.html