Skip to content

Commit

Permalink
In integration tests use a common AMI rather than hard coded per test (
Browse files Browse the repository at this point in the history
…ansible-collections#1067)

In integration tests use a common AMI rather than hard coded per test

Depends-On: ansible-collections#1068
SUMMARY
Rather than hard coding the AMIs on a per-test basis, use a common AMI defined in setup_ec2_facts
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
ec2_asg_instance_refresh
ec2_asg_lifecycle_hook
ec2_asg_scheduled_action
ec2_launch_template
ec2_lc
ec2_metric_alarm
ec2_scaling_policy
elb_network_lb
elb_target
elb_target_info
ADDITIONAL INFORMATION

Reviewed-by: Markus Bergholz <[email protected]>
Reviewed-by: Jill R <None>

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@3f434f3
  • Loading branch information
tremble authored and abikouo committed Oct 18, 2024
1 parent 30505b9 commit 8c803cd
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
---
ec2_ami_name: amzn2-ami-hvm-2.*-x86_64-gp2
test_role_name: ansible-test-{{ tiny_prefix }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies:
- prepare_tests
- setup_ec2
- setup_ec2_facts
- setup_remote_tmp_dir
- role: setup_botocore_pip
vars:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- name: Make instance with an instance_role
ec2_launch_template:
name: "{{ resource_prefix }}-test-instance-role"
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
instance_type: t2.micro
iam_instance_profile: "{{ test_role_name }}-1"
register: template_with_role
Expand All @@ -34,7 +34,7 @@
- name: Create template again, with no change to instance_role
ec2_launch_template:
name: "{{ resource_prefix }}-test-instance-role"
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
instance_type: t2.micro
iam_instance_profile: "{{ test_role_name }}-1"
register: template_with_role
Expand All @@ -47,7 +47,7 @@
- name: Update instance with new instance_role
ec2_launch_template:
name: "{{ resource_prefix }}-test-instance-role"
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
instance_type: t2.micro
iam_instance_profile: "{{ test_role_name }}-2"
register: template_with_updated_role
Expand All @@ -63,7 +63,7 @@
- name: Re-set with same new instance_role
ec2_launch_template:
name: "{{ resource_prefix }}-test-instance-role"
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
instance_type: t2.micro
iam_instance_profile: "{{ test_role_name }}-2"
register: template_with_updated_role
Expand All @@ -76,7 +76,7 @@
- name: Update instance with original instance_role (pass profile ARN)
ec2_launch_template:
name: "{{ resource_prefix }}-test-instance-role"
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
instance_type: t2.micro
# By default an instance profile will be created with the same name as the role
iam_instance_profile: '{{ iam_role.arn.replace(":role/", ":instance-profile/") }}'
Expand All @@ -93,7 +93,7 @@
- name: Re-set with same new instance_role (pass profile ARN)
ec2_launch_template:
name: "{{ resource_prefix }}-test-instance-role"
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
instance_type: t2.micro
iam_instance_profile: '{{ iam_role.arn.replace(":role/", ":instance-profile/") }}'
register: template_with_updated_role
Expand Down
9 changes: 0 additions & 9 deletions tests/integration/targets/ec2_launch_template/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@
security_token: "{{ security_token | default(omit) }}"
region: "{{ aws_region }}"
block:
- name: Find AMI to use
ec2_ami_info:
owners: 'amazon'
filters:
name: '{{ ec2_ami_name }}'
register: ec2_amis
- set_fact:
ec2_ami_image: '{{ ec2_amis.images[0].image_id }}'

- include_tasks: cpu_options.yml
- include_tasks: iam_instance_role.yml
- include_tasks: versions.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- name: create simple instance template
ec2_launch_template:
name: "{{ resource_prefix }}-simple"
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
tags:
TestId: "{{ resource_prefix }}"
instance_type: c4.large
Expand All @@ -20,7 +20,7 @@
ec2_launch_template:
name: "{{ resource_prefix }}-simple"
default_version: 1
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
tags:
TestId: "{{ resource_prefix }}"
instance_type: m5.large
Expand All @@ -37,7 +37,7 @@
- name: update simple instance template
ec2_launch_template:
name: "{{ resource_prefix }}-simple"
image_id: "{{ ec2_ami_image }}"
image_id: "{{ ec2_ami_id }}"
tags:
TestId: "{{ resource_prefix }}"
instance_type: t3.medium
Expand Down

0 comments on commit 8c803cd

Please sign in to comment.