Right, I saw that.... I don't understand why in the example you gave you are referencing item.1.* and then using a when statement of item.0
On Thursday, February 22, 2018 at 4:55:59 PM UTC-7, Matt Martz wrote: > > It allows you to loop 2 parallel sets of data. > > See > http://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-parallel-sets-of-data > > > On Thu, Feb 22, 2018 at 5:24 PM, John Harmon <[email protected] > <javascript:>> wrote: > >> Thanks. with_together is new to me. I am having a hard time wrapping my >> mind around the example you gave. Can you explain it to me? >> >> On Thursday, February 22, 2018 at 3:40:31 PM UTC-7, Matt Martz wrote: >>> >>> I think instead of doing that, you should use `with_together` and a >>> single `when` statement that meets your needs >>> >>> ... >>> line: "{{ item.1.line }}" >>> regexp: "{{ item1.regexp }}" >>> ... >>> when: item.0.stat.exists >>> with_together: >>> - "{{ directories.results }}" >>> - >>> - { line: '-w /home/GOMER/Scripts -p w -k copperfield', regexp: >>> '.*GOMER.*Scripts.*' } >>> - { line: '-w /home/PYLE/Scripts -p w -k copperfield', regexp: >>> '.*PYLE*Scripts.*' } >>> >>> On Thu, Feb 22, 2018 at 4:28 PM, John Harmon <[email protected]> >>> wrote: >>> >>>> For reference, this is a continuation of: >>>> https://groups.google.com/forum/#!topic/ansible-project/XhU9iPXjjcw >>>> >>>> Can you use multiple when statements in a loop? or is there a different >>>> way to approach this without having to write out a task for each item? >>>> Take the following for example. I know the syntax is wrong, but it >>>> gives you a better idea of what I mean. >>>> >>>> - name: Insert audit rules >>>> lineinfile: >>>> path: "/etc/audit/audit.rules" >>>> line: "{{ item.line }}" >>>> regexp: "{{ item.regexp }}" >>>> state: present >>>> insertafter: EOF >>>> notify: Restart auditd >>>> with_items: >>>> - { line: '-w /home/GOMER/Scripts -p w -k copperfield', regexp: >>>> '.*GOMER.*Scripts.*' } >>>> when: directories.results.0.stat.exists >>>> - { line: '-w /home/PYLE/Scripts -p w -k copperfield', regexp: >>>> '.*PYLE*Scripts.*' } >>>> when: directories.results.1.stat.exists >>>> >>>> >>>> -- >>>> 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/d5c1708b-13f8-4dd0-858c-dfacd40cdc2a%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/ansible-project/d5c1708b-13f8-4dd0-858c-dfacd40cdc2a%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> >>> -- >>> Matt Martz >>> @sivel >>> sivel.net >>> >> -- >> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/c0d13b53-c95d-4a73-84c1-8f2777067766%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/c0d13b53-c95d-4a73-84c1-8f2777067766%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Matt Martz > @sivel > sivel.net > -- 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/9b66bb32-7d7c-4327-ba57-a91ea1d7b93a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
