VARIABLE IS NOT DEFINED!

20 views
Skip to first unread message

Surjeet Singh

unread,
Jan 20, 2018, 2:26:57 AM1/20/18
to Ansible Project
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 
---
- name: collect device facts and display OS version
  hosts: "{{ inventory | default('all') }}"
  gather_facts: no
  connection: local

  
  tasks:
    - name: run the show commands
      ios_command:
        commands:
          - show version
        host: "{{ inventory_hostname }}"
        username: cisco
        password: cisco
      register: version
      
    - debug: var=version.stdout[0].Version

J Hawkesworth

unread,
Jan 23, 2018, 3:05:15 AM1/23/18
to Ansible Project
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

Surjeet Singh

unread,
Jan 23, 2018, 5:54:21 AM1/23/18
to ansible...@googlegroups.com
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. 

Regards,
Surjeet Singh
Technical Specialist – Networks DATA
CCNA, CCNP(R&S)
Cell : +917838707047

To become bigger person,need to walk with bigger Vision !!!!


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/2Ys9ni8oVak/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b69b0955-06ef-48e1-ad6d-1a1e918eeb57%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Jan 23, 2018, 9:57:45 AM1/23/18
to ansible...@googlegroups.com
On Saturday, 20 January 2018 08.26.56 CET Surjeet Singh wrote:
> ---
> - name: collect device facts and display OS version
> hosts: "{{ inventory | default('all') }}"
> gather_facts: no
> connection: local
>
>
> tasks:
> - name: run the show commands
> ios_command:
> commands:
> - show version
> host: "{{ inventory_hostname }}"
> username: cisco
> password: cisco
> register: version
>
> - debug: var=version.stdout[0].Version

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.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages