From c40832af482c3cc7b0c291ead5228ca582593419 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 18 Dec 2019 21:53:57 +0100 Subject: [PATCH] ec2_launch_template: Add default_version and latest_version to output, matching the documentation (#61279) - Add tests for default/latest version manipulation --- .../61279-ec2_launch_template-output.yml | 2 + .../cloud/amazon/ec2_launch_template.py | 4 ++ .../roles/ec2_launch_template/tasks/main.yml | 1 + .../ec2_launch_template/tasks/versions.yml | 62 +++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 changelogs/fragments/61279-ec2_launch_template-output.yml create mode 100644 test/integration/targets/ec2_launch_template/playbooks/roles/ec2_launch_template/tasks/versions.yml diff --git a/changelogs/fragments/61279-ec2_launch_template-output.yml b/changelogs/fragments/61279-ec2_launch_template-output.yml new file mode 100644 index 0000000000..176ef4eff0 --- /dev/null +++ b/changelogs/fragments/61279-ec2_launch_template-output.yml @@ -0,0 +1,2 @@ +bugfixes: +- ec2_launch_template - Update output to include latest_version and default_version, matching the documentation diff --git a/lib/ansible/modules/cloud/amazon/ec2_launch_template.py b/lib/ansible/modules/cloud/amazon/ec2_launch_template.py index 8804aa5e9a..f64dfb53fc 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_launch_template.py +++ b/lib/ansible/modules/cloud/amazon/ec2_launch_template.py @@ -556,6 +556,10 @@ def format_module_output(module): int(v['version_number']) == int(template['latest_version_number']) ) ][0] + if "version_number" in output['default_template']: + output['default_version'] = output['default_template']['version_number'] + if "version_number" in output['latest_template']: + output['latest_version'] = output['latest_template']['version_number'] return output diff --git a/test/integration/targets/ec2_launch_template/playbooks/roles/ec2_launch_template/tasks/main.yml b/test/integration/targets/ec2_launch_template/playbooks/roles/ec2_launch_template/tasks/main.yml index a36898f1d8..4976da276e 100644 --- a/test/integration/targets/ec2_launch_template/playbooks/roles/ec2_launch_template/tasks/main.yml +++ b/test/integration/targets/ec2_launch_template/playbooks/roles/ec2_launch_template/tasks/main.yml @@ -17,6 +17,7 @@ block: - include_tasks: cpu_options.yml - include_tasks: iam_instance_role.yml + - include_tasks: versions.yml always: - debug: diff --git a/test/integration/targets/ec2_launch_template/playbooks/roles/ec2_launch_template/tasks/versions.yml b/test/integration/targets/ec2_launch_template/playbooks/roles/ec2_launch_template/tasks/versions.yml new file mode 100644 index 0000000000..9035467a60 --- /dev/null +++ b/test/integration/targets/ec2_launch_template/playbooks/roles/ec2_launch_template/tasks/versions.yml @@ -0,0 +1,62 @@ +- block: + - name: create simple instance template + ec2_launch_template: + name: "{{ resource_prefix }}-simple" + image_id: "{{ ec2_ami_image[aws_region] }}" + tags: + TestId: "{{ resource_prefix }}" + instance_type: c4.large + register: lt + + - name: instance with cpu_options created with the right options + assert: + that: + - lt is success + - lt is changed + - lt.default_version == 1 + - lt.latest_version == 1 + + - name: update simple instance template + ec2_launch_template: + name: "{{ resource_prefix }}-simple" + default_version: 1 + image_id: "{{ ec2_ami_image[aws_region] }}" + tags: + TestId: "{{ resource_prefix }}" + instance_type: m5.large + register: lt + + - name: instance with cpu_options created with the right options + assert: + that: + - lt is success + - lt is changed + - lt.default_version == 1 + - lt.latest_version == 2 + + - name: update simple instance template + ec2_launch_template: + name: "{{ resource_prefix }}-simple" + image_id: "{{ ec2_ami_image[aws_region] }}" + tags: + TestId: "{{ resource_prefix }}" + instance_type: t3.medium + register: lt + + - name: instance with cpu_options created with the right options + assert: + that: + - lt is success + - lt is changed + - lt.default_version == 3 + - lt.latest_version == 3 + + always: + - name: delete the template + ec2_launch_template: + name: "{{ resource_prefix }}-simple" + state: absent + register: del_lt + retries: 10 + until: del_lt is not failed + ignore_errors: true