You could choose to define the "with_items" list in your group_vars/<whichever> or another variable file to make that a little cleaner.
The complex conditional is definitely available, though a little unusual. It might be more common to check to see if a file exists with the "stat" module -- asking the remote system, rather than the configuration if it needs something. If you have more than one role configuring something, only copy that last log file in the role that needs it. On Mon, Oct 27, 2014 at 11:10 AM, Tore Olsen <[email protected]> wrote: > Hi, > > > I want to use logentries to forward important log files. Most servers have > the same files, but there are some which are specific based on which > services are running. So I figured out one way to do this by using > with_items like the example below, but I'm not sure if this is considered a > good practice. The programmer in me instinctively wanted to define a > variable in group_vars/all and append to it (like a "subclass") in > group_vars/my_custom_server but that doesn't seem to be possible(?). > > > Or should I just create one task for the generic case and another task for > the more specific one? > > > What's the idiomatic way to do this in ansible? > > > -Tore > > > > --- > > - hosts: all > > > vars: > > - has_particular_file: no # or yes; to see the different behaviour > > > tasks: > > - name: Test > > action: debug msg="{{ item.file }}" > > with_items: > > - { file: /var/log/foo.log } > > - { file: /var/log/bar.log } > > - { file: /var/log/particular.log, cond: "{{ has_particular_file }}" } > > when: item.cond is not defined or item.cond|bool > > -- > 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/62451252-1540-483f-988a-d6c1f799f800%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/62451252-1540-483f-988a-d6c1f799f800%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%2BnsWgxEYOYsXyvVqNP%2B0uXM4qhrQdOqJfsNFQomGrsYYi66vQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
