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
On Saturday, January 20, 2018 at 7:26:57 AM UTC, Surjeet Singh wrote:
>
> 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
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
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.