VARIABLE IS NOT DEFINED!

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

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

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.

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.