default(omit) fails to omit param and place_holder is used as variable data

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

The output in the AWS console.

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.

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?

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.

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.