I’m deploying a system to an number of machines in EC2 and am seeing some weird behavior with variable expansion
I have group_vars where I define a target version for my system and versions for components a, b and c. Typically a, b and c use the same target version, but I need the ability to override each
with a different version. I’ve been modelling this as a varaibles file all in group_vars containing
target_version: 12345
a_version: “{{target_version}}”
b_version: “{{target_version}}”
c_version: “{{target_version}}”
For the most part this works well, the following play
- hosts: localhost
connection: local
tasks: - debug: var=target_version
- debug: var=a_version
expands as expected to
TASK: [debug var=target_version] **********************************************
ok: [127.0.0.1] => {
“target_version”: “12345”
}
TASK: [debug var=a_version] ****************************************
ok: [127.0.0.1] => {
“a_version”: “12345”
}
However when I spin up my EC2 instance and retrieve the facts,
-
hosts: ec2cluster
gather_facts: True
user: ansible
sudo: True
tasks: -
ec2_facts:
-
debug: var=hostvars[inventory_hostname]
these appear unexpanded as follows
“hostvars[inventory_hostname]”: {
“a_version”: “{{target_version}}”,
Also I pass in a variable containing instance tags that I’d like to add to the machine. I see that these get to the instance in the AWS console, but are not returned as ec2 facts like I’d have expected.
Are these bugs, or am I doing something wrong?
thanks,
Steve.