Playbooks In Subdirectories #12862

I’ve decided to drop my two cents in here as well since I have spent the past hour trawling Google for advice about this issue and found nothing that I consider to be an acceptable solution.

In my opinion, Ansible’s behavior when moving playbooks into a subdirectory (but still running them from the root directory) is unintuitive and doesn’t seem to match how other programs work. I could enumerate all of the things that stop working, but I think it’s sufficient to say that the expected behavior for the majority of people would be as follows:

Given that my directory structure is exactly the same as the layout shown in http://docs.ansible.com/ansible/latest/playbooks_best_practices.html#directory-layout, and I am running my scripts from the Ansible root directory like:

cd /path/to/project/ansible
ansible-playbook site.yml

If I copy site.yml into any subdirectory of the Ansible root folder:

mkdir -p playbooks/subdir
cp site.yml playbooks
cp site.yml playbook/subdir

Then the following commands should all be identical:

ansible-playbook site.yml
ansible-playbook playbooks/site.yml
ansible-playbook playbooks/subdir/site.yml

In the 2+ years I have been using Ansible, I haven’t encountered a situation where the current default behavior would have been beneficial compared to the behavior I outlined above. I feel like most people run their Ansible scripts from the Ansible root directory and mentally treat that as the directory that Ansible should be searching for vars/roles/inventory/etc, especially since the ansible.cfg is located there.

It would be really great if there was a setting that would make Ansible behave in the way I have outlined. I would suggest a boolean variable called something like lock_working_dir or lock_base_dir that would “lock” Ansible to the pwd when searching for vars/roles/inventory/etc.

This would be a huge boon for organization. I’m happy to have a go at this if this is something that would get considered for PR.

I feel like most people run their Ansible scripts from the Ansible root directory and mentally treat that as the directory that Ansible should be searching for vars/roles/inventory/etc, especially since the ansible.cfg is located there.

Your last two years must’ve been bloody awful.

Hi Varun,

What are you implying?