How to skip a hash if it's empty

318 views
Skip to first unread message

Samnang Sen

unread,
Jun 30, 2014, 3:02:28 PM6/30/14
to ansible...@googlegroups.com
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


Michael DeHaan

unread,
Jun 30, 2014, 5:05:18 PM6/30/14
to ansible...@googlegroups.com
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 <- tracker lives here.

Thanks!

--Michael


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f6e985b1-ad32-44ed-86f4-9abed5d77f31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages