combining vars facts and other data

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

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.

This answered my question perfectly. Thank you!