You can't say "when:" twice, but you can feed it a list. when: - item.useApplication - other_conditional
What you are doing with building a variable name in a conditional is a little weird, and this doesn't work. Rather, register when used with "with_items" will return an array, which you can easily debug: - stat: path=/etc/.git register: stats with_items: hosts when: item.useApplication - debug: var=stats Though ultimately, it looks like you should drop the lineinfile and just include your logic in a template, and it will be much cleaner and easier. On Mon, Aug 25, 2014 at 4:46 AM, Bastian Bringenberg < [email protected]> wrote: > Hey ho, > > I would like to deploy an application to several vhosts is > item.useApplication exists. I am possible to do that, download files and so > on and so on. But I get a problem as soon as I want to do an action if the > application is never installed. > > Normally: > > - stat: path=/etc/.git > register: exists_git > ignore_errors: yes > > - lineinfile: dest=/etc/rkhunter.conf line='ALLOWHIDDENDIR="/etc/.git"' > owner=root group=root mode=0644 > when: exists_git.stat.exists > > > But how is it possible for me to do this combined with "with_items"? One > approach, that (untested) will not work in my opinion: > > - stat: path=/etc/.git > register: exists_git_{{ item.name }} > with_items: hosts > when: item.useApplication > ignore_errors: yes > > - lineinfile: dest=/etc/rkhunter.conf line='ALLOWHIDDENDIR="/etc/.git"' > owner=root group=root mode=0644 > with_items: hosts > when: item.useApplication > when: exists_git_{{ item.name }}.stat.exists > > > Is someone able to help me here? > > Have a nice week, > Greetings from Bochum, RuhrArea, Germany, > > Bastian > > > PS: rkhunter is just a demonstration how I do this normally^^. > > -- > 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/2ced1119-8fda-4ace-a27b-db3879280f55%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/2ced1119-8fda-4ace-a27b-db3879280f55%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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%2BnsWgxWa3O298BBd6c2NqRPbQ0%3Da8PeaX8FquF7mdNin%2BgK-w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
