conditional question

Hi,

Is there a recommended way to set the value of a var based on remote machine architecture? i.e., i’d like to download file A on x86_64 and file B on i386.

Normally, I would use the ‘where’ clause, but this variable would be used in multiple tasks, so in that case I’d need to duplicate my list of tasks, one for each arch. This is, of course, not the end of the world, but I thought I’d check to see if there’s a better option?

Thanks,
Liam

I’m still new to this, but this may at least start guiding you in a “right” direction:

https://coderwall.com/p/fcarvw

I really need to unlink coderwall as a lot of the online examples are out of date and I don’t have a great way to edit all of them.

However, the above linked article is really only about checking remote facts to see what variables are available. There’s a bit more to it.

You probably should look into a “include_vars” which is documented here:

http://ansibleworks.com/docs/modules.html#include-vars

  • include_vars: “{{ ansible_architecture }}.yml”

etc

Got it - thanks!

Michaels' answer is better in most cases, but there is another way which
I occasionally use for simple things. In a vars file, do:

    foo: "{{ 'bar' if ansible_architecture == 'i386' else 'zoo' }}"

Only thing to watch out for is that the jinja2 expression must always
evaluate to *something*, so you'll virtually always need an else clause.