Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2_launch_template - scrub None parameters from what we'll pass to create_launch_config #413

Merged
merged 3 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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