# ansible Playbook execution failed with error:  "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'package'

**URL:** <https://forum.ansible.com/t/ansible-playbook-execution-failed-with-error-the-task-includes-an-option-with-an-undefined-variable-the-error-was-dict-object-has-no-attribute-package/32783>\
**Category:** Ansible Project\
**Created:** [April 25, 2020, 9:32pm UTC](https://forum.ansible.com/t/ansible-playbook-execution-failed-with-error-the-task-includes-an-option-with-an-undefined-variable-the-error-was-dict-object-has-no-attribute-package/32783 "2020-04-25T21:32:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mitesh\_Bhandari](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mitesh\_Bhandari](https://forum.ansible.com/u/Mitesh_Bhandari)\
**Post date:** [April 25, 2020, 9:32pm UTC](https://forum.ansible.com/t/ansible-playbook-execution-failed-with-error-the-task-includes-an-option-with-an-undefined-variable-the-error-was-dict-object-has-no-attribute-package/32783/1 "2020-04-25T21:32:01Z")

</div>

Hello,

I am new learner, trying to get hands on inclusions, where I am using include\_vars & include, however playbook execution is falling with an undefined variable error.

[user@node0101 veriable\_include]$ ansible-playbook -i inventory myplaybook.yml  
PLAY [Install Some Package] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [node0102]  
TASK [include variables from varPackage.yml] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [node0102]  
TASK [Install {{ vars.package }} package] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [node0102]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘package’\n\nThe error appears to be in ‘/home/user/veriable\_include/tasks.yml’: line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n—\n- name: Install {{ vars.package }} package\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”}  
PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
node0102 : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0  
[user@node0101 veriable\_include]$

[user@node0101 veriable\_include]$ pwd  
/home/user/veriable\_include

[user@node0101 veriable\_include]$ ls -l  
total 20  
-rw-rw-r–. 1 user user 93 Apr 25 17:57 ansible.cfg  
-rw-rw-r–. 1 user user 24 Apr 25 16:31 inventory  
-rw-rw-r–. 1 user user 208 Apr 26 02:51 myplaybook.yml  
-rw-rw-r–. 1 user user 247 Apr 26 02:51 tasks.yml  
-rw-rw-r–. 1 user user 71 Apr 26 02:52 varPackage.yml

**Following are the yml files & playbooks content:**

[user@node0101 veriable\_include]$ **cat varPackage.yml**

---

<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:** [April 26, 2020, 4:42am UTC](https://forum.ansible.com/t/ansible-playbook-execution-failed-with-error-the-task-includes-an-option-with-an-undefined-variable-the-error-was-dict-object-has-no-attribute-package/32783/2 "2020-04-26T04:42:03Z")

</div>

> Hello,
> 
> I am new learner, trying to get hands on inclusions, where I am using include\_vars & include, however playbook execution is falling with an undefined variable error.
> 
> [user@node0101 veriable\_include]$ ansible-playbook -i inventory myplaybook.yml  
> PLAY [Install Some Package] \*\*\*\*\*\*\*\*\*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\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [node0102]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘package’\n\nThe error appears to be in ‘/home/user/veriable\_include/tasks.yml’: line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n—\n- name: Install {{ vars.package }} package\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”}  
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> node0102 : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0  
> [user@node0101 veriable\_include]$
> 
> [user@node0101 veriable\_include]$ pwd  
> /home/user/veriable\_include
> 
> [user@node0101 veriable\_include]$ ls -l  
> total 20  
> -rw-rw-r–. 1 user user 93 Apr 25 17:57 ansible.cfg  
> -rw-rw-r–. 1 user user 24 Apr 25 16:31 inventory  
> -rw-rw-r–. 1 user user 208 Apr 26 02:51 myplaybook.yml  
> -rw-rw-r–. 1 user user 247 Apr 26 02:51 tasks.yml  
> -rw-rw-r–. 1 user user 71 Apr 26 02:52 varPackage.yml
> 
> **Following are the yml files & playbooks content:**
> 
> ## [user@node0101 veriable\_include]$ **cat varPackage.yml**
> 
> vars:  
> package: samba  
> service: smb  
> state: started  
> enabled: true
> 
> ## [user@node0101 veriable\_include]$ **cat tasks.yml**
> 
> - name: Install {{ vars.package }} package  
> yum:  
> name: “{{ vars.package }}”  
> state: latest
> - name: Start {{ vars.service }} service  
> service:  
> name: “{{ vars.service }}”  
> state: “{{ vars.state }}”  
> enabled: “{{ vars.enabled }}”

You don’t need to mention ‘vars’, just the variable itself, i.e. “{{ package }}”.

---

<div class="post-metadata">

**Author:** ![Mitesh\_Bhandari](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mitesh\_Bhandari](https://forum.ansible.com/u/Mitesh_Bhandari)\
**Post date:** [April 26, 2020, 8:23pm UTC](https://forum.ansible.com/t/ansible-playbook-execution-failed-with-error-the-task-includes-an-option-with-an-undefined-variable-the-error-was-dict-object-has-no-attribute-package/32783/3 "2020-04-26T20:23:24Z")

</div>

Hello Visser,

Thank you very much looking in to, I have already tried by referencing variable {{ package }} but same error.

[user@node0101 veriable\_include]$ ansible-playbook -i inventory myplaybook.yml  
PLAY [Install Some Package] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [node0102]  
TASK [include veriables from varPackages.yml] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [node0102]  
TASK [Install {{ package }} package] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [node0102]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘package’ is undefined\n\nThe error appears to be in ‘/home/user/veriable\_include/tasks.yml’: line 4, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n include\_vars: varPackage.yml\n- name: Install {{ package }} package\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”}  
PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
node0102 : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0  
[user@node0101 \_include]$

[user@node0101 veriable\_include]$ **cat tasks.yml**

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 26, 2020, 8:39pm UTC](https://forum.ansible.com/t/ansible-playbook-execution-failed-with-error-the-task-includes-an-option-with-an-undefined-variable-the-error-was-dict-object-has-no-attribute-package/32783/4 "2020-04-26T20:39:56Z")

</div>

vars is a reserved word in Ansible so you need to choose another name for your variable.

---

<div class="post-metadata">

**Author:** ![Mitesh\_Bhandari](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Mitesh\_Bhandari](https://forum.ansible.com/u/Mitesh_Bhandari)\
**Post date:** [April 27, 2020, 9:09am UTC](https://forum.ansible.com/t/ansible-playbook-execution-failed-with-error-the-task-includes-an-option-with-an-undefined-variable-the-error-was-dict-object-has-no-attribute-package/32783/5 "2020-04-27T09:09:36Z")

</div>

Hello Kai,

Thanks for help, I changed variable name other than vars and issue resolved.

[user@node0101 veriable\_include]$ cat varPackage.yml
