cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
956
Views
0
Helpful
5
Replies

Ansible variables not recognized

Gioacchino
Level 1
Level 1

Hi, I'm going through this tutorial to learn ansible with Cisco 9k3

https://developer.cisco.com/learning/modules/intro-ansible-iosxe/ansible-ios-modules/gather-information/

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

5 Replies 5

Gioacchino
Level 1
Level 1

Really no one has encountered this issue earlier?

Gio

Gioacchino
Level 1
Level 1

Who should define this variable or where this variable should have been already defined?

Ben Hobday
Level 1
Level 1

Hi Gio, did you figure this out? I'm now stuck on the same thing and new to it all.

@Ben Hobday,

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

asherpat1
Level 1
Level 1

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

Review Cisco Networking for a $25 gift card