# ansible 2.4 reports an error when extra var is passed

**URL:** <https://forum.ansible.com/t/ansible-2-4-reports-an-error-when-extra-var-is-passed/26227>\
**Category:** Ansible Project\
**Created:** [December 8, 2017, 11:33am UTC](https://forum.ansible.com/t/ansible-2-4-reports-an-error-when-extra-var-is-passed/26227 "2017-12-08T11:33:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmoullia](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cmoullia](https://forum.ansible.com/u/cmoullia)\
**Post date:** [December 8, 2017, 11:33am UTC](https://forum.ansible.com/t/ansible-2-4-reports-an-error-when-extra-var-is-passed/26227/1 "2017-12-08T11:33:09Z")

</div>

Hi

ansible playbook reports an error when one of the value of the yaml config file imported as var is passed on the command line using -e

Yaml Config File

`

---

<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:** [December 8, 2017, 11:53am UTC](https://forum.ansible.com/t/ansible-2-4-reports-an-error-when-extra-var-is-passed/26227/2 "2017-12-08T11:53:23Z")

</div>

> ansible playbook reports an error when one of the value of the yaml config  
> file imported as var is passed on the command line using -e
> 
> Yaml Config File
> 
> #  
> # Istio  
> #  
> istio:  
> &nbsp;&nbsp;github\_url: [https://api.github.com/repos](https://api.github.com/repos)  
> &nbsp;&nbsp;repo: istio/istio
> 
> &nbsp;&nbsp;# Could be a tag "0.2.12" version or be empty "", then in this case, the  
> latest release will be downloaded  
> &nbsp;&nbsp;release\_tag\_name: "0.2.12"  
> &nbsp;&nbsp;  
> &nbsp;&nbsp;# Folder where you want to install the distro on your machine. By  
> default, we will install it here ~/.istio  
> &nbsp;&nbsp;dest: "$HOME/.istio"
> 
> Command
> 
> ansible-playbook ansible/main.yml --extra-vars "{'istio':  
> {'release\_tag\_name': 0.3.0}}" -t install-istio -v
> 
> Result
> 
> TASK [Define var containing Istio dir]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [localhost]: FAILED! =\> {"failed": true, "msg": "The task includes  
> an option with an undefined variable. The error was: 'dict object' has no  
> attribute 'dest'\n\nThe error appears to have been in  
> '/Users/dabou/Code/istio/installation/ansible/istio/set\_istio\_distro\_dir.yml':  
> line 7, 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: Define  
> var containing Istio dir\n ^ here\n\nexception type: \<class  
> 'ansible.errors.AnsibleUndefinedVariable'\>\nexception: 'dict object' has no  
> attribute 'dest'"}
> 
> So, for a reason that I don't know, ansible is not able to find the  
> istio.dest variable

Because you overwritten the variable on the command line.

> The playbook doesn't report error when no '-e' var is passed to the  
> command !!!!!

I guess it has default dict that include dest.

> What could be the issue ?

When you overwrite a dict you need to provide everything since it's not possible to just change part of it.

---

<div class="post-metadata">

**Author:** ![cmoullia](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cmoullia](https://forum.ansible.com/u/cmoullia)\
**Post date:** [December 8, 2017, 1:06pm UTC](https://forum.ansible.com/t/ansible-2-4-reports-an-error-when-extra-var-is-passed/26227/3 "2017-12-08T13:06:12Z")

</div>

Which strategy do you propose then to be able to override a key=value defined within a yaml ?

---

<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:** [December 8, 2017, 2:20pm UTC](https://forum.ansible.com/t/ansible-2-4-reports-an-error-when-extra-var-is-passed/26227/4 "2017-12-08T14:20:35Z")

</div>

Instead of using dict, flatten it and use key value.

istio:  
&nbsp;&nbsp;&nbsp;dest: something  
&nbsp;&nbsp;&nbsp;release\_tab\_name: 0.2.12

Becomes  
istio\_dest: something  
istro\_release\_tab\_name: 0.2.12

Then you can easily override the individual variables.
