Skip to content

Commit

Permalink
inventory_aws_ec2/test: switch to ec2_instance (ansible-collections#480)
Browse files Browse the repository at this point in the history
inventory_aws_ec2/test: switch to ec2_instance

SUMMARY

Migrate the inventory_aws_ec2 tests from ec2 to ec2_instance.
Also, properly clean up all the resources during the test

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
inventory_aws_ec2

Reviewed-by: Mark Chappell <None>
Reviewed-by: Gonéri Le Bouder <[email protected]>
Reviewed-by: None <None>
  • Loading branch information
goneri authored Aug 31, 2021
1 parent e8df917 commit 776dd16
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@
# Create new host, add it to inventory and then terminate it without updating the cache

- name: create a new host
ec2:
image: '{{ image_id }}'
exact_count: 1
count_tag:
Name: '{{ resource_prefix }}'
instance_tags:
Name: '{{ resource_prefix }}'
ec2_instance:
image_id: '{{ image_id }}'
name: '{{ resource_prefix }}'
instance_type: t2.micro
wait: yes
group_id: '{{ sg_id }}'
wait: no
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
register: setup_instance

Expand All @@ -46,14 +42,12 @@
always:

- name: remove setup ec2 instance
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: '{{ sg_id }}'
name: '{{ resource_prefix }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
ignore_errors: yes
when: setup_instance is defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
owner-id: '125523088429'
virtualization-type: hvm
root-device-type: ebs
name: 'Fedora-Atomic-27*'
name: 'Fedora-Cloud-Base-34-1.2.x86_64*'
register: fedora_images

- set_fact:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@
# Create new host, refresh inventory, remove host, refresh inventory

- name: create a new host
ec2:
image: '{{ image_id }}'
exact_count: 1
count_tag:
Name: '{{ resource_prefix }}'
instance_tags:
Name: '{{ resource_prefix }}'
ec2_instance:
image_id: '{{ image_id }}'
name: '{{ resource_prefix }}'
instance_type: t2.micro
wait: yes
group_id: '{{ sg_id }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
wait: no
register: setup_instance

- meta: refresh_inventory
Expand All @@ -50,14 +46,12 @@
- "groups.aws_ec2.0 == '{{ resource_prefix }}'"

- name: remove setup ec2 instance
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: '{{ sg_id }}'
name: '{{ resource_prefix }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'

- meta: refresh_inventory
Expand All @@ -71,14 +65,12 @@
always:

- name: remove setup ec2 instance
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: '{{ sg_id }}'
name: '{{ resource_prefix }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
ignore_errors: yes
when: setup_instance is defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@

# Create new host, refresh inventory
- name: create a new host
ec2:
image: '{{ image_id }}'
exact_count: 1
count_tag:
Name: '{{ resource_prefix }}'
instance_tags:
Name: '{{ resource_prefix }}'
ec2_instance:
image_id: '{{ image_id }}'
name: '{{ resource_prefix }}'
tags:
OtherTag: value
instance_type: t2.micro
wait: yes
group_id: '{{ sg_id }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
wait: no
register: setup_instance

- meta: refresh_inventory
Expand All @@ -46,14 +43,12 @@
always:

- name: remove setup ec2 instance
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: "{{ sg_id }}"
name: '{{ resource_prefix }}'
security_groups: "{{ sg_id }}"
vpc_subnet_id: "{{ subnet_id }}"
ignore_errors: yes
when: setup_instance is defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@
# Create new host, refresh inventory

- name: create a new host
ec2:
image: '{{ image_id }}'
exact_count: 1
count_tag:
Name: '{{ resource_prefix }}'
instance_tags:
Name: '{{ resource_prefix }}'
ec2_instance:
image_id: '{{ image_id }}'
name: '{{ resource_prefix }}'
tags:
tag1: value1
tag2: value2
instance_type: t2.micro
wait: yes
group_id: '{{ sg_id }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
wait: no
register: setup_instance

- meta: refresh_inventory
Expand All @@ -59,14 +56,12 @@
always:

- name: remove setup ec2 instance
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: "{{ sg_id }}"
name: '{{ resource_prefix }}'
security_groups: "{{ sg_id }}"
vpc_subnet_id: "{{ subnet_id }}"
ignore_errors: yes
when: setup_instance is defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,39 @@

# Create new host, refresh inventory
- name: create a new host (1/3)
ec2:
image: '{{ image_id }}'
exact_count: 1
count_tag:
Name: '{{ resource_prefix }}_1'
instance_tags:
Name: '{{ resource_prefix }}_1'
ec2_instance:
image_id: '{{ image_id }}'
name: '{{ resource_prefix }}_1'
tags:
tag_instance1: foo
instance_type: t2.micro
wait: yes
group_id: '{{ sg_id }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
wait: no
register: setup_instance_1

- name: create a new host (2/3)
ec2:
image: '{{ image_id }}'
exact_count: 1
count_tag:
Name: '{{ resource_prefix }}_2'
instance_tags:
Name: '{{ resource_prefix }}_2'
ec2_instance:
image_id: '{{ image_id }}'
name: '{{ resource_prefix }}_2'
tags:
tag_instance2: bar
instance_type: t2.micro
wait: yes
group_id: '{{ sg_id }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
wait: no
register: setup_instance_2

- name: create a new host (3/3)
ec2:
image: '{{ image_id }}'
exact_count: 1
count_tag:
Name: '{{ resource_prefix }}_3'
instance_tags:
Name: '{{ resource_prefix }}_3'
ec2_instance:
image_id: '{{ image_id }}'
name: '{{ resource_prefix }}_3'
tags:
tag_instance2: bar
instance_type: t2.micro
wait: yes
group_id: '{{ sg_id }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
wait: no
register: setup_instance_3

- meta: refresh_inventory
Expand All @@ -77,40 +68,34 @@
always:

- name: remove setup ec2 instance (1/3)
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance_1.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: "{{ sg_id }}"
name: '{{ resource_prefix }}_1'
security_groups: "{{ sg_id }}"
vpc_subnet_id: "{{ subnet_id }}"
ignore_errors: yes
when: setup_instance_1 is defined

- name: remove setup ec2 instance (2/3)
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance_2.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: "{{ sg_id }}"
name: '{{ resource_prefix }}_2'
security_groups: "{{ sg_id }}"
vpc_subnet_id: "{{ subnet_id }}"
ignore_errors: yes
when: setup_instance_2 is defined

- name: remove setup ec2 instance (3/3)
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance_3.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: "{{ sg_id }}"
name: '{{ resource_prefix }}_3'
security_groups: "{{ sg_id }}"
vpc_subnet_id: "{{ subnet_id }}"
ignore_errors: yes
when: setup_instance_3 is defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@

# Create new host, refresh inventory
- name: create a new host
ec2:
image: '{{ image_id }}'
exact_count: 1
count_tag:
Name: '{{ resource_prefix }}:/aa'
instance_tags:
Name: '{{ resource_prefix }}:/aa'
ec2_instance:
image_id: '{{ image_id }}'
name: '{{ resource_prefix }}:/aa'
tags:
OtherTag: value
instance_type: t2.micro
wait: yes
group_id: '{{ sg_id }}'
security_groups: '{{ sg_id }}'
vpc_subnet_id: '{{ subnet_id }}'
wait: no
register: setup_instance

- meta: refresh_inventory
Expand All @@ -47,14 +44,12 @@
always:

- name: remove setup ec2 instance
ec2:
ec2_instance:
instance_type: t2.micro
instance_ids: '{{ setup_instance.instance_ids }}'
state: absent
wait: yes
instance_tags:
Name: '{{ resource_prefix }}'
group_id: "{{ sg_id }}"
name: '{{ resource_prefix }}'
security_groups: "{{ sg_id }}"
vpc_subnet_id: "{{ subnet_id }}"
ignore_errors: yes
when: setup_instance is defined
Expand Down
Loading

0 comments on commit 776dd16

Please sign in to comment.