Reputation: 13
I've just installed Ansible on Ubuntu 19.04.
The environment variable, ANSIBLE_CONFIG
is empty.
I have a local ansible.cfg
file pointing to a local inventory file (called hosts).
The local inventory file (hosts) identifies two routers (R1 and R2).
These devices, R1 and R2, are in my /etc/hosts file, and I can SSH to them.
ansible --version
shows my config file is /home/paddy/ansible.cfg
.
ansible --list-hosts all
says there's no hosts file.
When I remove the local ansible.cfg
file, and put the local inventory file (hosts) into /etc/ansible
, and then run, I get:
$ansible --list-hosts all
hosts (2):
R1
R2
This is as expected.
Unfortunately, when I use the local ansible.cfg
file, it doesn't see the inventory file (/home/paddy/hosts
)
$echo $ANSIBLE_CONFIG
<nothing>
ansible.cfg
file (in /home/paddy
) is as follows: [defaults]
hostfile = /home/paddy/hosts
host_key_checking = False
timeout = 5
/home/paddy
called hosts
): [routers]
R1
R2
/home/paddy
:$ls -l
total 52
-rw-r--r-- 1 paddy paddy 79 Aug 19 16:54 ansible.cfg
-rw-r--r-- 1 paddy paddy 17 Aug 19 16:55 hosts
<redacted directories>
ansible --version
$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.
$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):
I expected to see:
$ansible --list-hosts all
hosts (2):
R1
R2
What I get is:
$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):
Upvotes: 1
Views: 4572
Reputation: 68294
The Ini Key is inventory
Wrong
[defaults]
hostfile = /home/paddy/hosts
Correct
[defaults]
inventory = /home/paddy/hosts
Note
It's possible to use environment variables in ansible.cfg. For example
[defaults]
inventory = $PWD/hosts
roles_path = $PWD/roles
library = $PWD/modules:/usr/share/ansible/plugins/modules
...
Upvotes: 3