I am trying to create the Alternative Directory Layout from the Ansible docs site best practices section.
Following this guidance, here is the layout that I have created inside ~/ansible_proj/windows_setup
(windows_setup
is a Python virtual environment):
.venv
inventories/
production/
hosts
group_vars/
windows
windows.yml
vault
windows_configure.yml
roles/
role1/
role2/
role3/
role4/
.gitignore # this contains 1 line produced by: echo 'vault' >> .gitignore
When I try to run the playbook windows_configure.yml
, as suggested here (see 1st example), using
$ (.venv) cd ~/ansible_proj/windows_setup
$ (.venv) user@sname: ~/ansible_proj/windows_setup$ ansible-playbook
-i production windows_configure.yml --ask-vault-pass
the error is
Unable to parse /.../production as an inventory source
production hosts list is empty, only localhost is available
I must indicate the path to the hosts
file instead like:
$ (.venv) user@sname: ~/ansible_proj/windows_setup$ ansible-playbook
-i inventories/production/hosts windows_configure.yml --ask-vault-pass
in order for this to run.
Q1. How can I use the Alternative Directory Layout to run playbooks by using production
(as the docs suggest) instead of inventories/production/hosts
?
In the same directory structure, if I place windows_configure.yml
inside playbooks/
, and run with:
$ (.venv) user@sname: ~/ansible_proj/windows_setup$ ansible-playbook
-i inventories/production/hosts playbooks/windows_configure.yml
--ask-vault-pass
then I get this error
ERROR: the role 'role1' was not found in /.../playbooks/roles:/.../playbooks
Q2. In this Alternative Directory Structure, is it possible to place all playbooks inside a playbooks
directory?
EDIT
I have tried adding ansible.cfg
to the current directory (~/ansible_proj/windows_setup
) (which also contains the playbook windows_configure.yml
. Here is ansible.cfg
:
[defaults]
inventory = ~/ansible_proj/windows_setup/inventories/production
roles_path = ~/ansible_proj/windows_setup
When I run
$ (.venv) cd ~/ansible_proj/windows_setup
$ (.venv) user@sname: ~/ansible_proj/windows_setup$ ansible-playbook
-i production windows_configure.yml --ask-vault-pass
the same error appears
Unable to parse /.../production as an inventory source
production hosts list is empty, only localhost is available