Tom_Paine
(Tom Paine)
June 19, 2015, 8:36pm
1
When running this ec2 module task without the ‘build_number’ variable, the EC2 machine is created with a build tag of ‘__omit_place_holder__6248a11ef81332080f31b81d2894e811f905b723’ instead of being empty as expected.
Is the formatting wrong or is there a bug here?:
name: provision an instance
ec2:
ec2_access_key: “{{ ec2_access_key }}”
aws_secret_key: “{{ ec2_secret_key }}”
region: “{{ region }}”
key_name: “{{ key }}”
group: “{{ security_group_name }}”
instance_type: “{{instance_type }}”
monitoring: yes
image: “{{ instance_store_ami_data.ami }}”
vpc_subnet_id: “{{ subnet_euw1c }}”
assign_public_ip: yes
wait: true
exact_count: 1
count_tag:
role: sid
env: “{{ environment_name }}”
build: “{{ build_number | default(omit) }}”
instance_tags:
role: sid
env: “{{ environment_name }}”
build: “{{ build_number | default(omit) }}”
status: new
Tom_Paine
(Tom Paine)
June 19, 2015, 8:39pm
2
The output in the AWS console.
sivel
(sivel)
June 19, 2015, 9:24pm
3
That is due to “omit” only working for top level keys (arguments of the module) and not sub keys.
Maybe using “|default(‘’)” would work instead.
Tom_Paine
(Tom Paine)
June 19, 2015, 9:32pm
4
Alas, default(‘’) applies an empty tag which then shows up in the inventory.
I don’t see a ticket about this, may I raise an enhancement?
sivel
(sivel)
June 19, 2015, 9:55pm
5
I don’t see why not, logging an issue could result in adding such functionality.
Another thing to try in the meantime is to replace with a ‘~’. Quotes are probably necessary.
~ in YAML means None in Python.
Tom_Paine
(Tom Paine)
June 22, 2015, 12:24pm
6
Thanks Matt,
Without quotes:
Failed to template {{ build_number | default(~) }}: template error while templating string: unexpected ‘~’
With singles quotes it is not converted to null and simple taken as a string. Will raise an issue.