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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4aa27f5a-a00f-44d3-a176-b752be03c237%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to