# combining vars facts and other data

**URL:** <https://forum.ansible.com/t/combining-vars-facts-and-other-data/23512>\
**Category:** Ansible Project\
**Created:** [January 20, 2017, 4:41am UTC](https://forum.ansible.com/t/combining-vars-facts-and-other-data/23512 "2017-01-20T04:41:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Fitzgerald](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Greg\_Fitzgerald](https://forum.ansible.com/u/Greg_Fitzgerald)\
**Post date:** [January 20, 2017, 4:41am UTC](https://forum.ansible.com/t/combining-vars-facts-and-other-data/23512/1 "2017-01-20T04:41:06Z")

</div>

Hi,

I'm coming from chef, and in chef land we do a lot of fancy things in  
our attributes files.

For example in one of my cookbooks I do this.

node.default['ts3']['arch'] = node['kernel']['machine'] =~ /x86\_64/ ?  
"amd64" : "x86"

This returns either amd64 or x86 based on the architecture of the  
machine. I use this later to get the correct url for a download.

Can I do something like this in defaults/main.yml? If not is there some  
where I can do a similar calculation?

Best Regards,  
Greg Fitzgerald

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 20, 2017, 3:20pm UTC](https://forum.ansible.com/t/combining-vars-facts-and-other-data/23512/2 "2017-01-20T15:20:12Z")

</div>

> Hi,
> 
> I'm coming from chef, and in chef land we do a lot of fancy things in  
> our attributes files.
> 
> For example in one of my cookbooks I do this.
> 
> node.default['ts3']['arch'] = node['kernel']['machine'] =~ /x86\_64/ ?  
> "amd64" : "x86"
> 
> This returns either amd64 or x86 based on the architecture of the  
> machine. I use this later to get the correct url for a download.

I have never used Chef so I'm not sure what node.default['ts3']['arch'] does.

But to get amd64 or x84 in Ansible you can use this  
{{ (ansible\_architecture == 'i386') | ternary('x86', 'amd64') }}

> Can I do something like this in defaults/main.yml? If not is there some  
> where I can do a similar calculation?

If you mean in a role, the yes.

On the top level Ansible doesn't have defaults directory.  
It does have group\_vars and host\_vars but you can't use jinga templates in them.

You can use this in a task with set\_facts, in a plays vars: section or just use it like this where ever you need it.  
I also think you can use it in a file with include\_vars: directive.

---

<div class="post-metadata">

**Author:** ![Greg\_Fitzgerald](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Greg\_Fitzgerald](https://forum.ansible.com/u/Greg_Fitzgerald)\
**Post date:** [January 20, 2017, 4:06pm UTC](https://forum.ansible.com/t/combining-vars-facts-and-other-data/23512/3 "2017-01-20T16:06:45Z")

</div>

This answered my question perfectly. Thank you!
