Reputation: 170548
It seems that ansible assumes that the ansible.cfg file exists in the current working directory so when you try to call a playbook that exists in a subdirectory it will fail to load the roles and other stuff.
Is it possible to store playbook in different directories?
Please note that the ansible.cfg is part of the source code.
Upvotes: 3
Views: 5796
Reputation: 421
I was facing the same problem. I wanted to putt all the playbooks in a separate directory instead of having them all flying around in my base directory. My base directory is under git control an it contains a local ansible.cfg file with the following content:
[defaults]
inventory=hosts
roles_path=roles
By setting roles_path ansible with look for the roles directory in the base directory instead of the subdirectory of your playbooks. Be aware that if you have another directory with files you're referencing in your playbooks, you have to qualify this as followed:
- name: copy nagios config files
copy:
src: ../files/nagios3/config/
dest: /etc/nagios3/conf.d/
owner: root
group: root
notify: reload nagios
In this case the playbook is located in a playbooks subdirectoy at the same level as the files directory. Just like that:
.
├── README
├── ansible.cfg
├── files
│ └── ...
├── host_vars
│ └── ...
├── hosts
├── playbooks
│ └── ...
├── roles
│ └── ...
└── templates
└── ...
Upvotes: 2
Reputation: 13734
Per the documentation, Ansible will look for the configuration file in the following order:
So if you'd like to call playbooks from alternate directories, you can pass along ANSIBLE_CONFIG
pointing at the appropriate ansible.cfg
.
Upvotes: 4