Skip to content

Commit

Permalink
ec2_launch_template - scrub None parameters from what we'll pass to c…
Browse files Browse the repository at this point in the history
…reate_launch_config (ansible-collections#413)

* ec2_launch_template - scrub None parameters from what we'll pass to create_launch_config
* tests
* changelog
  • Loading branch information
tremble authored and danquixote committed May 16, 2021
1 parent 0ec1f94 commit b4d36da
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/230-ec2_launch_template-None-types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ec2_launch_template - ensure that empty parameters are properly removed before passing to AWS (https://github.com/ansible-collections/community.aws/issues/230).
2 changes: 2 additions & 0 deletions plugins/modules/ec2_launch_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@

from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.core import scrub_none_parameters
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ansible_dict_to_boto3_tag_list
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict
Expand Down Expand Up @@ -512,6 +513,7 @@ def create_or_update(module, template_options):
template, template_versions = existing_templates(module)
out = {}
lt_data = params_to_launch_data(module, dict((k, v) for k, v in module.params.items() if k in template_options))
lt_data = scrub_none_parameters(lt_data, descend_into_lists=True)
if not (template or template_versions):
# create a full new one
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- include_tasks: iam_instance_role.yml
- include_tasks: versions.yml
- include_tasks: instance-metadata.yml
- include_tasks: network_interfaces.yml

always:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
- block:
- name: network_interfaces
ec2_launch_template:
name: "{{ resource_prefix }}-test-nic"
state: present
network_interfaces:
- device_index: 0
associate_public_ip_address: false
delete_on_termination: true
- device_index: 1
associate_public_ip_address: true
delete_on_termination: false
ipv6_address_count: 1
register: nic_template
- name: instance with network_interfaces created with the right settings
assert:
that:
- nic_template is changed
- nic_template.default_template.launch_template_data.network_interfaces[0].associate_public_ip_address == False
- nic_template.default_template.launch_template_data.network_interfaces[0].delete_on_termination == True
- nic_template.default_template.launch_template_data.network_interfaces[0].device_index == 0
- nic_template.default_template.launch_template_data.network_interfaces[1].associate_public_ip_address == True
- nic_template.default_template.launch_template_data.network_interfaces[1].delete_on_termination == False
- nic_template.default_template.launch_template_data.network_interfaces[1].device_index == 1
- nic_template.default_template.launch_template_data.network_interfaces[1].ipv6_address_count == 1

- name: network_interfaces
ec2_launch_template:
name: "{{ resource_prefix }}-test-nic"
state: present
network_interfaces:
- device_index: 0
associate_public_ip_address: false
delete_on_termination: true
- device_index: 1
associate_public_ip_address: true
delete_on_termination: false
ipv6_address_count: 1
register: nic_template
- name: instance with network_interfaces created with the right settings
assert:
that:
- nic_template is not changed

always:
- name: delete the template
ec2_launch_template:
name: "{{ resource_prefix }}-test-nic"
state: absent
register: del_lt
retries: 10
until: del_lt is not failed
ignore_errors: true

0 comments on commit b4d36da

Please sign in to comment.