# How to skip a hash if it's empty

**URL:** <https://forum.ansible.com/t/how-to-skip-a-hash-if-its-empty/15576>\
**Category:** Ansible Project\
**Created:** [June 30, 2014, 7:02pm UTC](https://forum.ansible.com/t/how-to-skip-a-hash-if-its-empty/15576 "2014-06-30T19:02:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_S](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sam\_S](https://forum.ansible.com/u/Sam_S)\
**Post date:** [June 30, 2014, 7:02pm UTC](https://forum.ansible.com/t/how-to-skip-a-hash-if-its-empty/15576/1 "2014-06-30T19:02:28Z")

</div>

This could probably be done much better so any advice is welcome. I have a file called “deploy\_list” inside the “group\_vars” folder. It’s a list of modules that needs to be deployed. During any given deploy, the deployment person lists the modules he wishes to deploy. The list of modules differs for each deploy so the file is dynamic.

Without having to pass “–tags=perl” if he knows only PERL modules are being deployed, I would rather have the script skip the PHP tasks if no variables are set. See below … this would fail w/ the following msg.

TASK: [Export PHP code from SVN] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [127.0.0.1] =\> with\_dict expects a dict

# cat deploy\_list

deploy\_php\_modules:

deploy\_perl\_modules:  
module\_name:  
tag: ‘20140514r1\_6.21\_Amadeus’  
svn\_path: ‘/projects/module\_name’  
document\_root: ‘/tmp’

# cat site.yml

- hosts: 127.0.0.1  
gather\_facts: no  
connection: local  
user: deployment

vars\_files:

- “group\_vars/deploy\_list”

tasks:

- name: Export PHP code from SVN  
action: shell svn export {{ item.value.svn\_path }} {{ item.value.document\_root }}  
with\_dict: deploy\_php\_modules  
tags: php

- name: Export PERL code from SVN  
action: shell svn export {{ item.value.svn\_path }} {{ item.value.document\_root }}  
with\_dict: deploy\_perl\_modules  
tags: perl

---

<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 30, 2014, 9:05pm UTC](https://forum.ansible.com/t/how-to-skip-a-hash-if-its-empty/15576/2 "2014-06-30T21:05:12Z")

</div>

I think this is a case where we’d like a bug in GitHub, and it would be possible to make it be able to iterate over an empty dict.

[github.com/ansible/ansible](http://github.com/ansible/ansible) ← tracker lives here.

Thanks!

–Michael
