I’m using roles for template building, and would like to understand the use the of the vars directory a bit more. From the docs, I see that ansible will automatically pick up roles/{role}/vars/main.yml. But let’s say that I want to put multiple var files in the vars directory. Is there a way to tell ansible to pickup not only main.yml, but every other *.yml file in that directory as well?
Thank you, but this does not seem to be working. Are you sure it’s “var_files” and not “vars_files”? I’ve tried a number of options, with and without quotes around the filename, but no luck.
Actually i meant vars_files: but i guess even that doesn’t seem to work in vars/main.yml, so i guess the only option might be to include it in your main playbook. but i will wait for others to also comment.
With Vault especially, it seems like a sensible pattern to have a separate encrypted file in vars/ for credentials, next to main.yml
Having to specify include_vars or vars_files explicitly each time feels a little clumsy : shouldn’t one reasonably expect a directory named “vars” to have some magic meaning and consider all of its contents automatically (like group_vars and inventory directories do) ?
Since vars/ also doesn’t serve as a default path for include_vars in role tasks (AFAIK, you have to explicitly say “…/vars/xxx.yml”), technically it might as well be just “roles/x/vars.yml”, right ?