Hi Michael,
thanks for your reply. I did in fact modify my solution according to your
latest comment, by defining different roles and running multiple logentries
tasks. I realize it's simpler than attempting to dynamically build a list
of arguments.
I like your idea about testing the remote system with stat though. It would
be nice to define a list of common files in a group/whatever variable,
and use stat to filter. Do you think the following is an appropriate
solution?
tasks:
- name: Stat
action: stat path="{{ item }}"
with_items:
- "{{ files }}"
register: statreg
- name: Test
action: debug msg="{{ item.item }}"
with_items: statreg.results
when: item.stat.exists
Thanks again.
-Tore
On Thursday, October 30, 2014 9:19:01 PM UTC+1, Michael DeHaan wrote:
>
> 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]
> <javascript:>> 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] <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/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/cc9cf3a3-100d-4ff3-8b26-91b51fd58ffd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.