Double loop Ansible -


i have object that

objs:     - { key1: value1, key2: [value2, value3] }     - { key1: value4, key2: [value5, value6] } 

and i'd create following files

value1/value2 value1/value3 value4/value5 value4/value6 

but have no idea how double loop using with_items

yes. can.

take @ with_subelements in here http://docs.ansible.com/ansible/playbooks_loops.html#nested-loops

  1. you need create folders:
  2. iterate though objs , create files:

here example:

---  - hosts: localhost   gather_facts: no   vars:     objs:       - { key1: value1, key2: [ value2, value3] }       - { key1: value4, key2: [ value5, value6] }   tasks:      - name: create files       file: path="{{ item.key1 }}"  state=directory       with_items:         objs      - name: create files       file: path="{{ item.0.key1 }}/{{ item.1 }}"  state=touch       with_subelements:         - objs         - key2 

an output pretty self explanatory, second loop iterates through values way need it:

play [localhost] **************************************************************   task: [create files] **********************************************************  changed: [localhost] => (item={'key2': ['value2', 'value3'], 'key1': 'value1'}) changed: [localhost] => (item={'key2': ['value5', 'value6'], 'key1': 'value4'})  task: [create files] **********************************************************  changed: [localhost] => (item=({'key1': 'value1'}, 'value2')) changed: [localhost] => (item=({'key1': 'value1'}, 'value3')) changed: [localhost] => (item=({'key1': 'value4'}, 'value5')) changed: [localhost] => (item=({'key1': 'value4'}, 'value6'))  play recap ********************************************************************  localhost                  : ok=2    changed=2    unreachable=0    failed=0  

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -