conditional question

59 views
Skip to first unread message

Liam Staskawicz

unread,
Nov 29, 2013, 9:55:20 PM11/29/13
to ansible...@googlegroups.com
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

BrianAI

unread,
Nov 29, 2013, 11:30:20 PM11/29/13
to ansible...@googlegroups.com
I'm still new to this, but this may at least start guiding you in a "right" direction:

https://coderwall.com/p/fcarvw

Michael DeHaan

unread,
Nov 30, 2013, 7:57:35 AM11/30/13
to ansible...@googlegroups.com
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:


- include_vars: "{{ ansible_architecture }}.yml"

etc




On Fri, Nov 29, 2013 at 11:30 PM, BrianAI <brian.a....@gmail.com> wrote:
I'm still new to this, but this may at least start guiding you in a "right" direction:

https://coderwall.com/p/fcarvw

--
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-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Liam Staskawicz

unread,
Nov 30, 2013, 12:28:50 PM11/30/13
to ansible...@googlegroups.com
Got it - thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/XyfKa4RopVs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

C. Morgan Hamill

unread,
Dec 2, 2013, 2:28:29 PM12/2/13
to ansible-project
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.
--
Morgan Hamill
Reply all
Reply to author
Forward
0 new messages