# Escaping - and / in dictionary name

**URL:** <https://forum.ansible.com/t/escaping-and-in-dictionary-name/29426>\
**Category:** Ansible Project\
**Created:** [January 11, 2019, 6:36pm UTC](https://forum.ansible.com/t/escaping-and-in-dictionary-name/29426 "2019-01-11T18:36:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spiro\_Mitsialis](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Spiro\_Mitsialis](https://forum.ansible.com/u/Spiro_Mitsialis)\
**Post date:** [January 11, 2019, 6:36pm UTC](https://forum.ansible.com/t/escaping-and-in-dictionary-name/29426/1 "2019-01-11T18:36:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 11, 2019, 8:27pm UTC](https://forum.ansible.com/t/escaping-and-in-dictionary-name/29426/2 "2019-01-11T20:27:30Z")

</div>

When you have non supported character in the key, you need to use the notation, so instead of .admin-status you need to use ['admin-status']

---

<div class="post-metadata">

**Author:** ![Spiro\_Mitsialis](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Spiro\_Mitsialis](https://forum.ansible.com/u/Spiro_Mitsialis)\
**Post date:** [January 11, 2019, 9:01pm UTC](https://forum.ansible.com/t/escaping-and-in-dictionary-name/29426/3 "2019-01-11T21:01:29Z")

</div>

Thanks,

This works. I tried all sorts of combination with square brackets but not this.

Works for following as well:  
var: ansible\_facts.cisco\_ios.interfaces['**GigabitEthernet1/1/1’]**
