# Unable to fetch value from ansible\_devices variable if special charcter in key

**URL:** <https://forum.ansible.com/t/unable-to-fetch-value-from-ansible-devices-variable-if-special-charcter-in-key/15523>\
**Category:** Ansible Project\
**Created:** [June 23, 2014, 8:52am UTC](https://forum.ansible.com/t/unable-to-fetch-value-from-ansible-devices-variable-if-special-charcter-in-key/15523 "2014-06-23T08:52:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roopendra\_Vishwakarm](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Roopendra\_Vishwakarm](https://forum.ansible.com/u/Roopendra_Vishwakarm)\
**Post date:** [June 23, 2014, 8:52am UTC](https://forum.ansible.com/t/unable-to-fetch-value-from-ansible-devices-variable-if-special-charcter-in-key/15523/1 "2014-06-23T08:52:21Z")

</div>

I am using gather fact variable to get size from [ansible\_devices variable.](http://docs.ansible.com/playbooks_variables.html#information-discovered-from-systems-facts) for some host I am getting variable **`"ansible_devices": { "sda"`** and for few server getting **`"ansible_devices": { "cciss!c0d0"`.**

**Problem:-** When I am using variable **`{{`**** ` **` ansible\_devices.`** __``sda`.size`__ }} ` **`its working perfectly. But when I am trying to access value from {{ `** `ansible_devices.` ****`** `cciss!c0d0` **.size }}`** in my playbook `then it is not returning any value whereas in json ansible_devices variable there is value exist for ` **`{{ ansible_devices.`**** ` **`cciss!c0d0`**.size }}.`**

**``**

`  
{  
“ansible\_devices”: {  
“cciss!c0d0”: {  
“holders”: ,  
“host”: “RAID bus controller: Hewlett-Packard Company Smart Array Controller (rev 03)”,  
“model”: “LOGICAL VOLUME”,  
“partitions”: {},  
“removable”: “0”,  
“rotational”: “1”,  
“scheduler\_mode”: “cfq”,  
“sectors”: “143299800”,  
“sectorsize”: “512”,  
“size”: “68.33 GB”,  
“support\_discard”: “0”,  
“vendor”: “HP”  
}  
},  
“item”: “”  
}

`

It might be the case special character in a json key that’s why I am unable to fetch its value. can anyone suggest me how can I access **`{{ ansible_devices.`**** ` **`cciss!c0d0`**.size }} ` **`value here`** ` ?`**

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 23, 2014, 12:11pm UTC](https://forum.ansible.com/t/unable-to-fetch-value-from-ansible-devices-variable-if-special-charcter-in-key/15523/2 "2014-06-23T12:11:18Z")

</div>

That’s not a valid variable name, so you’ll have to attack it edgewise:

{{ hostvars[inventory\_hostname]["**`ansible_devices"]["`****`**`cciss!c0d0"]["`**size"] }}`**

**`Usage of set_fact would allow assigning it to a cleaner variable name.`**

---

<div class="post-metadata">

**Author:** ![Roopendra\_Vishwakarm](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@Roopendra\_Vishwakarm](https://forum.ansible.com/u/Roopendra_Vishwakarm)\
**Post date:** [June 24, 2014, 7:22am UTC](https://forum.ansible.com/t/unable-to-fetch-value-from-ansible-devices-variable-if-special-charcter-in-key/15523/3 "2014-06-24T07:22:50Z")

</div>

Thanks for your help. Nice Trick. Its working for me.
