While I'm not an Ansible developer, I can tell you static re-use items are processed before the play starts so they can be 'imported' at the start of the play. Include_* is dynamic while Import_* is static (vars_files is an import).
Imports: static re-use <https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse.html#imports-static-re-use> *Importing roles, tasks, or playbooks adds them to a playbook statically. Ansible pre-processes imported files and roles before it runs any tasks in a playbook, so imported content is never affected by other tasks within the top-level playbook. * On Tuesday, July 28, 2020 at 4:01:26 AM UTC-5 sten...@gmail.com wrote: > Hi all > > I know I have a custom setup, but I've discovered funny thing, not sure if > it's a bug or not, but maybe to see a second thought here. > > - name: webservers > hosts: webservers #it's a group in hosts file > > vars: > my_custom_variable: webservers > /-- output omitted --/ > > #vars_files: "{{ playbook_dir }}/{{ my_custom_variable }}_vault.yml" > #vars_files: "{{ playbook_dir }}/{{ansible_play_name}}_vault.yml" > > become: yes > roles: > - common > /-- output omitted --/ > > So, thing is with vars_files. > IF I use "my_custom_variable" then vault.yml file is located and used. > IF I use "ansible_play_name" then it's not and I get error saying > > ERROR! vars file {{ playbook_dir }}/{{ansible_play_name}}_vault.yml was > not found > Could not find file on the Ansible Controller. > If you are using a module and expect the file to exist on the remote, see > the remote_src option > > But when I enter debug and print out those variables inside playbook task, > then I can see that they are correct and point to correct names/directories. > > What am I missing here? Why I cannot use ansible_play_name inside > vars_files inside playbook. When I use the same variable inside template or > in same playbook tasks section, everything is correct and "webservers" is > used. > -- You received this message because you are subscribed to the Google Groups "Ansible Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/372ab3e4-c2d2-44e8-af79-2341e391b11cn%40googlegroups.com.