# ansible\_play\_name not available in playbook vars\_files

**URL:** <https://forum.ansible.com/t/ansible-play-name-not-available-in-playbook-vars-files/33508>\
**Category:** Ansible Developer\
**Created:** [July 28, 2020, 9:01am UTC](https://forum.ansible.com/t/ansible-play-name-not-available-in-playbook-vars-files/33508 "2020-07-28T09:01:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sten\_Aus](https://avatars.discourse-cdn.com/v4/letter/s/d26b3c/32.png) [@Sten\_Aus](https://forum.ansible.com/u/Sten_Aus)\
**Post date:** [July 28, 2020, 9:01am UTC](https://forum.ansible.com/t/ansible-play-name-not-available-in-playbook-vars-files/33508/1 "2020-07-28T09:01:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![James\_Lagermann](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@James\_Lagermann](https://forum.ansible.com/u/James_Lagermann)\
**Post date:** [November 26, 2020, 12:36am UTC](https://forum.ansible.com/t/ansible-play-name-not-available-in-playbook-vars-files/33508/2 "2020-11-26T00:36:32Z")

</div>

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._
