Alternatively, the group_by module is a great way to create a dynamic group
of hosts where something is true, and then apply tasks only to that group
of hosts.





On Tue, Apr 15, 2014 at 3:49 AM, Stephan S. <[email protected]> wrote:

> This will require again an extra file for the role. I was hoping to do
> everything inside a single playbook.
>
> Thank you very much for your reply.
>
>
> On Thursday, April 10, 2014 7:09:06 PM UTC+3, Paul Durivage wrote:
>
>> Using a role is the way to go here.  Yes, you'll need to physically crate
>> the role and use 3 files, but conditionally running the role with a "when"
>> statement is the only way, I think, that you can avoid writing "when: a ==
>> b" 10 times.
>>
>> Why do you need 3 files for your role?  You said it was simple, so I
>> think you'd only have one file in the role/tasks folder.
>>
>>
>>
>> On Wed, Apr 9, 2014 at 9:51 AM, Stephan S. <[email protected]> wrote:
>>
>>> Hello,
>>>
>>> i have a playbook which contains 10 tasks. I want to run those tasks
>>> only if a when clause if filled.
>>> My first approach was to put on every task the when. E.g.:
>>>
>>>
>>>
>>> *    - name: My command       command: sudo install....      when: a ==
>>> b*
>>>
>>> The above example worked fine but was not ideal. The second approach was
>>> to use roles. Inside a playbook i declared a role. This role contained a
>>> task list
>>> which was executed only when the 'when' was true. That worked as well
>>> but i needed 3 files for something really simple.
>>>
>>> My question is if i can have just one single playbook, including all 10
>>> tasks and control all those tasks with one just when clause,
>>> avoid to have always the same when: a == b for every task.
>>>
>>> Thank you
>>>
>>>  --
>>> 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/b9e6e451-5566-4126-b2d6-
>>> 63756869c25e%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/b9e6e451-5566-4126-b2d6-63756869c25e%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/72aacd22-15f6-4544-b39e-d1b59ba5311f%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/72aacd22-15f6-4544-b39e-d1b59ba5311f%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%2BnsWgw3EeoV561x27DKQftjOcy1LwdJ249%2BgYf8LXH7hZQv%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to