Hi,
I’m calling the ansible-network.cisco_cli parser to parse the show interface of a switchport. It returns the following:
“ansible_facts”: {
“cisco_ios”: {
“interfaces”: {
“GigabitEthernet1/0/1”: {
“admin-status”: “enabled”,
“counters”: {
“in-broadcast-pkts”: “67706”,
“in-multicast-pkts”: null,
“in-octets”: “4483218”,
“in-unicast-pkts”: “1680087045”,
“out-errors”: “0”,
“out-octets”: “9071817”,
“out-unicast-pkts”: “5628651075”
},
“description”: “test port 802.1x”,
“enabled”: true,
“mtu”: “9000”,
“name”: “GigabitEthernet1/0/1”,
“oper-status”: “down”,
“type”: “Gigabit Ethernet”
}
}
}
In my playbook I’m trying to display the admin-status which has a dash and is not allowed in a variable name. This comes from the parser. I get an error each time
- name: display output
debug:
var: ansible_facts.cisco_ios.interfaces[“{{ interface | lower | regex_replace(‘gi’,‘GigabitEthernet’) }}”].admin-status
The play works if I check counters:
- name: display output
debug:
var: ansible_facts.cisco_ios.interfaces[“{{ interface | lower | regex_replace(‘gi’,‘GigabitEthernet’) }}”].counters
So how can I escape the - in the admin-status?
Once this works I will use it with a when statement:
when: ansible_facts.cisco_ios.interfaces[“{{ interface | lower | regex_replace(‘gi’,‘GigabitEthernet’) }}”].admin-status == enabled
I have similar problem if I try to do the following, so I’m hoping that the same escape will work with the /:
- name: display output
debug:
var: ansible_facts.cisco_ios.interfaces.GigabitEthernet1/1/1
Thanks,
Spiro