08-02-2023 08:56 AM - edited 08-02-2023 08:57 AM
Hi, I'm going through this tutorial to learn ansible with Cisco 9k3
All has been good till the moment I tried to run this playbook (ansible-playbook -v -i hosts 02-ios_facts.yaml)
--- - name: Sample IOS playbook to retrieve facts hosts: iosxe gather_facts: no tasks: - name: retrieve ios facts cisco.ios.ios_facts: - name: display version and serial number debug: msg: "The IOS version is: {{ ansible_net_version }} and the SN is: {{ ansible_net_serialnum }}" - name: print out interface information debug: var: ansible_net_interfaces
Besides the warning
[WARNING]: ansible-pylibssh not installed, falling back to paramiko
eventualy I get
"ansible_net_interfaces": "VARIABLE IS NOT DEFINED!: 'ansible_net_interfaces' is undefined. 'ansible_net_interfaces' is undefined"
I had a look at this page
https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_user_module.html#ansible-collections-cisco-ios-ios-user-module
and I replaced the variable (ansible_net_interfaces) with others. Some are recognized (ansible_net_hostname), other are not (ansible_net_config).
Who's wrong? Me, Ansible or the IOS-XE version (17.09.03)?
If it is me, where am I wrong?
Thanks,
Gio
08-14-2023 12:16 AM
Really no one has encountered this issue earlier?
Gio
08-14-2023 02:11 AM
Who should define this variable or where this variable should have been already defined?
12-21-2023 06:58 AM
Hi Gio, did you figure this out? I'm now stuck on the same thing and new to it all.
01-04-2024 01:14 AM - edited 01-04-2024 01:23 AM
It's been a whilke that I haven't used it. I don't remember whether I have or I haven't found a solution
I have to resume work on this for sure in the future, at that moment I will update this thread.
Sorry,
Gio
06-11-2024 03:58 AM
Hi Gio,
I think its because the default 'gather subset' value in the cisco.ios.ios_facts module is set to min, meaning unless declared it will not gather many of those pre-defined variables
You need change the gather_subset parameter in the yaml file to either 'all' or to be more specific in your case 'interfaces'
Try this instead - it worked for me (my indentation might be bad sorry- i struggled to paste my yaml file and keep indentation but I ran this in my lab and it works)
---
- name: Sample IOS playbook to retrieve facts
hosts: iosxe
gather_facts: no
tasks:
- name: retrieve ios facts
cisco.ios.ios_facts:
gather_subset:
- interfaces
- name: display version and serial number
debug:
msg: "The IOS version is: {{ ansible_net_version }} and the SN is: {{ ansible_net_serialnum }}"
- name: print out interface information
debug:
var: ansible_net_interfaces
...
https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_facts_module.html#ansible-collections-cisco-ios-ios-facts-module - have a look at the 'gather_subset' parameter
Thanks
Asher
04-23-2025 12:51 PM
Asher's solution is correct, it needs the gather_subset parameter. The playbook also needs the
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide