# Manage dict with empty keys

**URL:** <https://forum.ansible.com/t/manage-dict-with-empty-keys/20196>\
**Category:** Ansible Project\
**Created:** [January 13, 2016, 1:04pm UTC](https://forum.ansible.com/t/manage-dict-with-empty-keys/20196 "2016-01-13T13:04:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_Mavro](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@Pierre\_Mavro](https://forum.ansible.com/u/Pierre_Mavro)\
**Post date:** [January 13, 2016, 1:04pm UTC](https://forum.ansible.com/t/manage-dict-with-empty-keys/20196/1 "2016-01-13T13:04:03Z")

</div>

Hi,

I’m trying to find a way to grab RabbitMQ plugins when an URL is specified as value of a key (because some of them are include but not activated with RabbitMQ, while others are not included).

I’d like to have a single dict containing both and in the case where a value is not specified, it’s implicitly included in RabiitMQ. Here is what I’ve got:

`

rabbitmq\_plugins:  
rabbitmq\_management:  
rabbitmq\_delayed\_message\_exchange: ‘[http://www.rabbitmq.com/community-plugins/v3.6.x/rabbitmq\_delayed\_message\_exchange-0.0.1.ez](http://www.rabbitmq.com/community-plugins/v3.6.x/rabbitmq_delayed_message_exchange-0.0.1.ez)’  
`

And in the role I’ve:

`

- name: download and install additionnal plugins  
get\_url: url={{item.value}} dest={{rabbitmq\_plugins\_folder}} owner=root group=root mode=0644  
with\_dict: rabbitmq\_plugins  
when: “item.key is defined”  
`

Unfortunately it fails like this:

`ok: [10.200.0.18] => (item={'key': 'rabbitmq_delayed_message_exchange', 'value': 'http://www.rabbitmq.com/community-plugins/v3.6.x/rabbitmq_delayed_message_exchange-0.0.1.ez'}) failed: [10.200.0.18] => (item={'key': 'rabbitmq_management', 'value': 'None'}) => {"failed": true, "item": {"key": "rabbitmq_management", "value": "None"}} msg: unknown url type: None`

If I modify the when statement like this: when: “item.key is defined or item.value is not Null”, I got:

`fatal: [10.200.0.18] => Failed to template {% if item.key is defined or item.value is not Null %} True {% else %} False {% endif %}: template error while templating string: no test named 'Null'`

Any idea how I can make it work properly ?

Thanks

---

<div class="post-metadata">

**Author:** ![Pierre\_Mavro](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@Pierre\_Mavro](https://forum.ansible.com/u/Pierre_Mavro)\
**Post date:** [January 17, 2016, 2:36pm UTC](https://forum.ansible.com/t/manage-dict-with-empty-keys/20196/2 "2016-01-17T14:36:34Z")

</div>

Nobody has an idea ☹ ?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 17, 2016, 2:58pm UTC](https://forum.ansible.com/t/manage-dict-with-empty-keys/20196/3 "2016-01-17T14:58:11Z")

</div>

I think your problem is that you are checking item.key. Item.key is always defined, as that is the name of the key. You want to check if item.value is something.

I would check something like:

when: item.value

That should be sufficient.

---

<div class="post-metadata">

**Author:** ![Pierre\_Mavro](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@Pierre\_Mavro](https://forum.ansible.com/u/Pierre_Mavro)\
**Post date:** [January 25, 2016, 2:01pm UTC](https://forum.ansible.com/t/manage-dict-with-empty-keys/20196/4 "2016-01-25T14:01:28Z")

</div>

Thanks it works with:

`when: "item.value is defined and item.value"`
