为什么Ansible会忽略我的库存文件?
我刚刚在Ubuntu 19.04上安装了Ansible。 环境变量为什么Ansible会忽略我的库存文件?,ansible,Ansible,我刚刚在Ubuntu 19.04上安装了Ansible。 环境变量ANSIBLE\u CONFIG为空。 我有一个本地ansible.cfg文件,指向一个本地清单文件(称为hosts)。 本地资源清册文件(主机)标识两个路由器(R1和R2)。 这些设备R1和R2位于我的/etc/hosts文件中,我可以通过SSH连接到它们。 ansible--version显示我的配置文件是/home/paddy/ansible.cfg。 ansible——列出所有主机表示没有主机文件 当我删除本地ansibl
ANSIBLE\u CONFIG
为空。
我有一个本地ansible.cfg
文件,指向一个本地清单文件(称为hosts)。
本地资源清册文件(主机)标识两个路由器(R1和R2)。
这些设备R1和R2位于我的/etc/hosts文件中,我可以通过SSH连接到它们。
ansible--version
显示我的配置文件是/home/paddy/ansible.cfg
。
ansible——列出所有主机
表示没有主机文件
当我删除本地ansible.cfg
文件,并将本地清单文件(主机)放入/etc/ansible
,然后运行时,我得到:
$ansible --list-hosts all
hosts (2):
R1
R2
这是意料之中的。
不幸的是,当我使用本地ansible.cfg
文件时,它没有看到清单文件(/home/paddy/hosts
)
/home/paddy
中称为hosts
):/home/paddy
中的文件:ansible--list的输出承载所有内容。
$ansible --list-hosts all
hosts (2):
R1
R2
我得到的是:
$ansible --list-hosts all
[WARNING]: provided hosts list is empty, only localhost is available.
Note that the implicit localhost does not match 'all'.
hosts (0):
Ini键是
错
正确的
[defaults]
inventory = /home/paddy/hosts
注 可以在ansible.cfg中使用环境变量。比如说
[defaults]
inventory = $PWD/hosts
roles_path = $PWD/roles
library = $PWD/modules:/usr/share/ansible/plugins/modules
...
$ansible --version
ansible 2.8.4
config file = /home/paddy/ansible.cfg
configured module search path = [u'/home/paddy/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.16 (default, Apr 6 2019, 01:42:57) [GCC 8.3.0]
$ansible --list-hosts all
[WARNING]: provided hosts list is empty, only localhost is available.
Note that the implicit localhost does not match 'all'.
hosts (0):
$ansible --list-hosts all
hosts (2):
R1
R2
$ansible --list-hosts all
[WARNING]: provided hosts list is empty, only localhost is available.
Note that the implicit localhost does not match 'all'.
hosts (0):
[defaults]
hostfile = /home/paddy/hosts
[defaults]
inventory = /home/paddy/hosts
[defaults]
inventory = $PWD/hosts
roles_path = $PWD/roles
library = $PWD/modules:/usr/share/ansible/plugins/modules
...