Currently I have one big var file (vars/apps.yml) and all my playbooks look like this:
name: my playbook
vars_files:
- vars/apps.yml
roles:
- somerole
This works, but now I'd like to change my setup. As my apps.yml
got really big and messy, I want to split it into multiple files (one file per app). So I need a possibility to load all vars files into my playbook. It is ok to change all my playbook once, but I do not want to change all my playbooks every time I add a new var file.
My 1. attempt was to have the multiple yml files plus an apps.yml
which includes all other files - so I don't have to change anything in my playbooks.
Sadly, var files doesn't support include.
My 2. attempt was to replace
vars_files:
- vars/apps.yml
with
include_vars:
dir: vars
But that also failed because include_vars
is only supported at tasks-level, not at playbook-level.
So now I'm out of ideas how to dynamically load multiple var files at playbook level.
Edit:
As there is some confusion, here is the full playbook I try to execute (using include_vars):
- name: debug
hosts: localhost
include_vars:
dir: vars
roles:
- apache
This leads to ERROR! 'include_vars' is not a valid attribute for a Play
And as it is mentioned here, include_vars
is only available under tasks.