2017-03-05 67 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