I've got a hack for what seems like a lack of "break" in ansible
loops. How ugly is that (and is there a better way)?

---------
play.xml

---
- hosts: all
  tasks:
    - file: path=/tmp/THISFAILED state=touch mode="0600"
    - custom: name="{{ item.name }}"
        msg="{{ item.msg }}"
        failme="{{ item.failme }}"
      with_items:
        - { name: 1, msg: first  , failme: notyet }
        - { name: 2, msg: second , failme: notyet }
        - { name: 3, msg: third  , failme: now }
        - { name: 4, msg: fourth , failme: notyet }
      when: lookup('file', '/tmp/THISFAILED') != "now"
  - file: path=/tmp/THISFAILED state=absent


------------------
modules/custom.py

#!/usr/bin/python

import os

def main():
   module = AnsibleModule(
       argument_spec = dict(
           name   = dict(required=True, type='str'),
           msg    = dict(required=True, type='str'),
           failme = dict(required=True, type='str'),
       ),
       supports_check_mode=False
   )

   results = {}
   results['name'] = module.params['name']
   results['msg'] = module.params['msg']

   f = open('/tmp/THISFAILED','w')
   f.write(module.params['failme'])

   module.exit_json(**results)

from ansible.module_utils.basic import *
main()

This produces, as expected:
TASK: [custom name="{{ item.name }}" msg="{{ item.msg }}" failme="{{
item.failme }}"] ***
ok: [localhost] => (item={'msg': 'first', 'failme': 'notyet', 'name': 1})
ok: [localhost] => (item={'msg': 'second', 'failme': 'notyet', 'name': 2})
ok: [localhost] => (item={'msg': 'third', 'failme': 'now', 'name': 3})
skipping: [localhost] => (item={'msg': 'fourth', 'failme': 'notyet', 'name': 4})


Regards,
Daniel

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CA%2BSnNS9v%3D-UiOBwuW6jzKGw0KSNv4nFkqFD4RKwHtySVLK7axw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to