ios_facts doesn't return output when used in playbook but shows output in ad-hoc command. Why?

37 views
Skip to first unread message

Vikram S

unread,
Mar 9, 2021, 9:10:33 AM3/9/21
to Ansible Project

Below is my playbook to gather ios_facts info in GNS3 router. The output shows "VARIABLE IS NOT DEFINED!"

But when i gather ios_facts using ad-hoc command, it works. Why the difference?

----------------------------------------------------------------------------------------

name: PLAYBOOK 1 hosts: R1 gather_facts: true connection: network_cli

  • vars: ansible_network_os: ios

    tasks:

    • name: IOS facts ios_facts: gather_subset: all

      register: print_output

    • debug: var=print_output.stdout_lines

OUTPUT: PLAY [PLAYBOOK 1] ***************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************************************** ok: [R1]

TASK [IOS facts] **************************************************************************************************************************************************************************************************************************** ok: [R1]

TASK [debug] ******************************************************************************************************************************************************************************************************************************** ok: [R1] => { "print_output.stdout_lines": "VARIABLE IS NOT DEFINED!" }

PLAY RECAP ********************************************************************************************************************************************************************************************************************************** R1 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0


--------------------------------------------------------------------------------------------------------------------------------

AD-HOC command:

ansible all -i "192.168.122.72", -c network_cli -u david-user -k -m ios_facts -e ansible_network_os=ios

SSH password:

[WARNING]: default value for gather_subset will be changed to min from !config v2.11 onwards 

192.168.122.72 | SUCCESS => { "ansible_facts": { "ansible_net_all_ipv4_addresses": [ "192.168.122.72" ], "ansible_net_all_ipv6_addresses": [], "ansible_net_api": "cliconf", "ansible_net_filesystems": [], "ansible_net_filesystems_info": {},

Dick Visser

unread,
Mar 9, 2021, 9:25:38 AM3/9/21
to ansible...@googlegroups.com
On Tue, 9 Mar 2021 at 15:10, Vikram S <vikrams...@gmail.com> wrote:
>
> Below is my playbook to gather ios_facts info in GNS3 router. The output shows "VARIABLE IS NOT DEFINED!"
>
> But when i gather ios_facts using ad-hoc command, it works. Why the difference?

The facts are gathered and prefixed with 'ansible_net_' (like
ansible_net_all_ipv4_addresses).
You should not use register.
Reply all
Reply to author
Forward
0 new messages