You'll notice that the official recommendations for directory layout put all of the playbooks at the root level. This is intentional, as Ansible doesn't handle other schemes well.
You can put playbooks in a subdirectory, as you've started to do, but that will require (as you've already found) the use of relative paths from the playbooks to any other resources they use; Ansible uses the playbook path to start its search, that's just how it's written. For the most part, that's just what you get to deal with when you make the choice to move where playbooks live.
However, you seem to have more nesting than you should:
---
- hosts: aws_instance.jenkins-agents
user: ec2-user
vars_files:
- ../../../vars/main.yaml
- ../../../vars/vault.yaml
...
Why are you navigating up three directories? I'd expect a layout that's like the official one, but with one subfolder for playbooks; then you'd end up with just
---
- hosts: aws_instance.jenkins-agents
user: ec2-user
vars_files:
- ../vars/main.yaml
- ../vars/vault.yaml
...
which is a much more minor change.
Secondly, it's pretty rare that you actually want to use vars_files
. Most variables used in Ansible either vary based on the host (and thus should go in group_vars
/host_vars
in the project root) or are role-specific (and thus should go in vars
/defaults
in the role directory). A few documentation links:
Personally, I think it's best to have as little as possible in your playbooks, but delegate everything out to roles. Here's an example entire playbook in your setup:
- hosts: aws_instance.jenkins-agents
roles:
- ../roles/jenkins_agent
This gives you far more flexibility for re-use.
And if you find yourself not wanting to use relative paths for roles, you can override roles_path
in an ansible.cfg
in the root directory where you run your Ansible commands from.
../../../vars
?