I personally strongly dislike seeing Jinja2 conditionals in top level
playbooks (too much like line noise), so I'd do this to keep it cleaner:
- shell: foo
register: x
- shell: bar
register: y
- shell: baz
register: z
- set_fact: a={{ z }}
- set_fact: a={{ y }}
when: x
On Tue, Jun 3, 2014 at 12:41 PM, Adam Morris <[email protected]> wrote:
>
>
> On Tuesday, June 3, 2014 12:17:39 AM UTC-7, arnej wrote:
>>
>> Hi,
>>
>> this is probably easy but I cannot figure out how to do this with Ansible:
>>
>> - some task that registers variable x
>> - some task that registers variable y
>> - some task that registers variable z
>>
>> - register a variable 'a' for which holds: if x == True, a=y, else, a=z
>>
>> - some task that uses a
>>
>> How can this be done with Ansible? I currently use two conditional tasks
>> for the assignment and register the variable 'a' with a shell echo command
>> -- this does not seem right to me ;)
>>
>>
>> All the best
>> Arne
>>
>
> It might be possible to work around this with jinja, but I am reminded of
> the words of the guru... "Ansible is not a programming language"...
>
> Can I suggest instead...
>
> Some task that registers variable X
>
> Another task that registers variable a but is only run when X is true
>
> A third task that registers variable a but is only run when X is false
>
> A fourth task that uses variable a
>
> Unless you need both y and z at the same time then this satisfies your use
> case and simplifies your actual playbook...
>
> Of course even this might not be needed depending on what you are actually
> trying to do.
>
> I hope that this helps,
>
>
> Adam
>
> --
> 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/4aa27f5a-a00f-44d3-a176-b752be03c237%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/4aa27f5a-a00f-44d3-a176-b752be03c237%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%2BnsWgyHz1XO4Ly%3DBuPpVu4%3DQ_WEQpGtq369vyJerDY-5aj0mw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.