vars_files- use of variables in filename

Hi,

I am including a vars file in my playbook as follows:

vars_files:

  • vars/{{((test|default(‘’)).ansible|default(‘’)).vars|default(‘install.yml’)}}

test.ansible.vars is passed from the cli.

However, I am seeing ansible.errors.AnsibleFileNotFound: vars file vars/{{((test|default(‘’)).ansible|default(‘’)).vars|default(‘install.yml’)}} was not found when running the playbook. Anything I am doing wrong?

To my knowledge vars_files doesn't support jinja template, you can use the include_vars instead.

it does support templating, that expression makes no sense to me.

He’s breaking it into pieces and creating defaults lol

  • vars/{{ ( (test | default(‘’) ).ansible|default(‘’)).vars | default(‘install.yml’) }}

@Varun Chopra First of all, I don’t think there is anything to “lol” about here. If you don’t know something you ask. And if you know something you either help the other person understand/stay silent.

The reason I had a default for each level is because there could be cases where test or test.ansible are not defined as indicated in comment here (https://github.com/ansible/ansible/issues/41507#issuecomment-397069455)

you realize that '' cannot have .anything? you need default({}) to
make it a dictionary, which CAN have keys

I didn't use a list in vars_files: so that why it failed for me, with a list I see it support templating.

Ah makes sense, thanks bcoca!

Did you get offended? I’m sorry. I hope you didn’t burst a vein.