# Unable to load variable from include\_vars into my playbook

**URL:** <https://forum.ansible.com/t/unable-to-load-variable-from-include-vars-into-my-playbook/32319>\
**Category:** Ansible Project\
**Created:** [February 24, 2020, 6:17pm UTC](https://forum.ansible.com/t/unable-to-load-variable-from-include-vars-into-my-playbook/32319 "2020-02-24T18:17:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [February 24, 2020, 6:17pm UTC](https://forum.ansible.com/t/unable-to-load-variable-from-include-vars-into-my-playbook/32319/1 "2020-02-24T18:17:48Z")

</div>

I have a playbook where I load a variable file

`  
cat vars/BASE.yaml

EXCLUDE\_front: value1  
EXCLUDE\_back: value2  
`

I run my test.yml playbook using this command:

`  
ansible-playbook test.yml -e Layer=“back” -e base\_folder=“/tmp”

- name: Load a variable file"  
include\_vars:  
file: “vars/BASE.yaml”

- name: Collect data  
shell: “cd {{ base\_folder }} && find . -type d \( -name ‘BACKUP’ -o -name ‘vars[EXCLUDE\_{{ Layer }}]’ \) -prune -o -type f -exec cksum {} + | awk ‘{$1=""}1’”  
register: outputfiles

`

I also tried

`shell: "cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o -name 'vars[EXCLUDE_ + Layer]' \\) -prune -o -type f -exec cksum {} + | awk '{$1=\"\"}1'"`

and

`shell: "cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o -name 'vars[EXCLUDE_ ~ Layer]' \\) -prune -o -type f -exec cksum {} + | awk '{$1=\"\"}1'"`

however, instead of loading value1 or value2, I get the below nature of error:

> "The task includes an option with an undefined variable. The error was: ‘EXCLUDE\_’ is undefined\n\nT

```auto

```

```auto
Can you please suggest what is wrong with my playbook? 

```

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [February 24, 2020, 8:52pm UTC](https://forum.ansible.com/t/unable-to-load-variable-from-include-vars-into-my-playbook/32319/2 "2020-02-24T20:52:44Z")

</div>

You can’t resolve variables with names that contain variables themselves.

Instead, use a lookup:

[https://docs.ansible.com/ansible/latest/plugins/lookup/vars.html](https://docs.ansible.com/ansible/latest/plugins/lookup/vars.html)

Also try to use the args: chdir option instead of doing &&, see  
[https://docs.ansible.com/ansible/latest/modules/shell\_module.html](https://docs.ansible.com/ansible/latest/modules/shell_module.html)

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 25, 2020, 6:42pm UTC](https://forum.ansible.com/t/unable-to-load-variable-from-include-vars-into-my-playbook/32319/3 "2020-02-25T18:42:44Z")

</div>

> You can’t resolve variables with names that contain variables themselves.  
> Instead, use a lookup:
> 
> [https://docs.ansible.com/ansible/latest/plugins/lookup/vars.html](https://docs.ansible.com/ansible/latest/plugins/lookup/vars.html)
> 
> Also try to use the args: chdir option instead of doing &&, see  
> [https://docs.ansible.com/ansible/latest/modules/shell\_module.html](https://docs.ansible.com/ansible/latest/modules/shell_module.html)

"{{ vars['EXCLUDE\_' + Layer] }}" should work though.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [February 26, 2020, 7:53am UTC](https://forum.ansible.com/t/unable-to-load-variable-from-include-vars-into-my-playbook/32319/4 "2020-02-26T07:53:40Z")

</div>

It’s works. Thank you Stefen
