
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 412 Views
Where to put inventory file for offline role
Hello,
I duplicated the inventory file whereever I could. Despites that, the ansible offline role that I created with the dev hosts group could not point to the right inventory.
[maw@controlnode ansible]$ ansible-navigator run -m stdout apache_role.yml --syntax-check
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
[WARNING]: Could not match supplied host pattern, ignoring: dev
playbook: /home/maw/ansible/apache_role.yml
[maw@controlnode ansible]$
Please, help
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 311 Views
Hello,
By default ansible-navigator gets the ansible configuration from /etc/ansible/ansible.cfg, and expects /etc/ansible/hosts as the default inventory file. Best practice is to not use /etc/ansible, but to create a per-project ansible.cfg file and inventory.
Navigator will also look for ansible.cfg in the current working directory. What I usually do is create a separate directory for each project, and place playbooks, roles, etc. in that directory.
Your ansible.cfg can be as simple as 2 lines, like below, and would go in the project_dir:
[defaults]
inventory = /home/username/project_dir/inventory
You can also specify the inventory file on the command line with navigator:
ansible-navigator run playbook.yml -i /path/to/inventory/file
You can run ansible-config init --disabled > ansible_config_sample.cfg
to get a file with all possible options for ansible.cfg. It has very good explanations in the comments.