Hi,
I would like to use ec2-create module outputs as variable and pass it to other roles, this is playbook structure;
Instead of using set_fact, I would suggest
`
- debug var={{ item.id }}
with_items: ec2_create_result.instances
`
set_fact is basically around to allow cases where you get an integer back from something and something else needs that value multiplied by 10 or 3 or something. It’s a very niche module, that somehow gets overused.
It also really likes to mangle types unless you use it in complex_args mode like so:
- set_fact:
x: y.foo
So it doesn’t go through stringification.
Anyway…“I would like to use ec2-create module outputs as variable and pass it to other roles, this is playbook structure;”
In this case, just do the register, and ec2_create_result could be referenced in your other roles, and that would likely be easiest.
I’ve used this;
action:
module: ec2
image: “{{ aws_ami }}”
instance_type: “{{ aws_instance_type }}”
state: present
wait: yes
ec2_access_key: “{{ ec2_access_key }}”
ec2_secret_key: “{{ ec2_secret_key }}”
register: ec2_create_result
…
debug: var={{ec2_create_result.instances[0].public_ip
Thanks all.
The “var” param on the debug module is used to output specific variables and does not take a Jinja2 template as a parameter, as what you are then feeding to “var” is the result of the template evaluation - templating happens first.
It seems you want:
debug: msg=“My value is {{ foo }}”