# VARIABLE IS NOT DEFINED!

**URL:** <https://forum.ansible.com/t/variable-is-not-defined/26521>\
**Category:** Ansible Project\
**Created:** [January 20, 2018, 7:26am UTC](https://forum.ansible.com/t/variable-is-not-defined/26521 "2018-01-20T07:26:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Surjeet\_Singh](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@Surjeet\_Singh](https://forum.ansible.com/u/Surjeet_Singh)\
**Post date:** [January 20, 2018, 7:26am UTC](https://forum.ansible.com/t/variable-is-not-defined/26521/1 "2018-01-20T07:26:56Z")

</div>

am i impacted with some bug ?

“VARIABLE IS NOT DEFINED!”

root@eve-ng:/etc/ansible# ansible-playbook test.yaml

PLAY [collect device facts and display OS version] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [run the show commands] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[WARNING]: argument username has been deprecated and will be removed in a future version  
[WARNING]: argument host has been deprecated and will be removed in a future version  
[WARNING]: argument password has been deprecated and will be removed in a future version  
ok: [8.8.8.8]  
ok: [5.5.5.5]

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [8.8.8.8] =\> {  
“version.stdout[0].Version”: “VARIABLE IS NOT DEFINED!”  
}  
ok: [5.5.5.5] =\> {  
“version.stdout[0].Version”: “VARIABLE IS NOT DEFINED!”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
5.5.5.5 : ok=2 changed=0 unreachable=0 failed=0  
8.8.8.8 : ok=2 changed=0 unreachable=0 failed=0

root@eve-ng:/etc/ansible# more test.yaml

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [January 23, 2018, 8:05am UTC](https://forum.ansible.com/t/variable-is-not-defined/26521/2 "2018-01-23T08:05:14Z")

</div>

I think you just need to set

`gather_facts: yes`

otherwise host-related variables, such as  
`inventory_hostname`

won’t exist when you come to use them later in your playbook.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Surjeet\_Singh](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@Surjeet\_Singh](https://forum.ansible.com/u/Surjeet_Singh)\
**Post date:** [January 23, 2018, 10:54am UTC](https://forum.ansible.com/t/variable-is-not-defined/26521/3 "2018-01-23T10:54:08Z")

</div>

Hi jon,

I think that’s not the reason. i can debug my variable used with register command. indeed i can debug the variable.

it seems now i have issue with regular expression and i am try to find good source how to use regular expr.

---

<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:** [January 23, 2018, 2:57pm UTC](https://forum.ansible.com/t/variable-is-not-defined/26521/4 "2018-01-23T14:57:25Z")

</div>

I have never used ios\_command, but my guess is that version.stdout[0] is a string not dictionary with the key Version in it.
