-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd6b212
commit 6780504
Showing
3 changed files
with
120 additions
and
114 deletions.
There are no files selected for viewing
121 changes: 61 additions & 60 deletions
121
tests/integration/targets/inventory_aws_ec2/tasks/setup.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,62 @@ | ||
- name: get image ID to create an instance | ||
amazon.aws.ec2_ami_info: | ||
filters: | ||
architecture: x86_64 | ||
# CentOS Community Platform Engineering (CPE) | ||
owner-id: '125523088429' | ||
virtualization-type: hvm | ||
root-device-type: ebs | ||
name: 'Fedora-Cloud-Base-34-1.2.x86_64*' | ||
register: fedora_images | ||
|
||
- set_fact: | ||
image_id: '{{ fedora_images.images.0.image_id }}' | ||
vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' | ||
subnet_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/24' | ||
|
||
- name: create a VPC to work in | ||
amazon.aws.ec2_vpc_net: | ||
cidr_block: '{{ vpc_cidr }}' | ||
state: present | ||
name: '{{ resource_prefix }}_setup' | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_setup' | ||
register: setup_vpc | ||
|
||
- set_fact: | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
|
||
- name: create a subnet to use for creating an ec2 instance | ||
amazon.aws.ec2_vpc_subnet: | ||
az: '{{ aws_region }}a' | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
cidr: '{{ subnet_cidr }}' | ||
state: present | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_setup' | ||
register: setup_subnet | ||
|
||
- set_fact: | ||
subnet_id: '{{ setup_subnet.subnet.id }}' | ||
|
||
- name: create a security group to use for creating an ec2 instance | ||
ec2_security_group: | ||
name: '{{ resource_prefix }}_setup' | ||
description: 'created by Ansible integration tests' | ||
state: present | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
register: setup_sg | ||
|
||
- set_fact: | ||
sg_id: '{{ setup_sg.group_id }}' | ||
|
||
- name: Create ec2 instance | ||
ec2_instance: | ||
image_id: '{{ image_id }}' | ||
name: '{{ resource_prefix }}' | ||
instance_type: t2.micro | ||
security_groups: '{{ sg_id }}' | ||
vpc_subnet_id: '{{ subnet_id }}' | ||
wait: no | ||
register: setup_instance | ||
tasks: | ||
- amazon.aws.ec2_ami_info: | ||
filters: | ||
architecture: x86_64 | ||
# CentOS Community Platform Engineering (CPE) | ||
owner-id: '125523088429' | ||
virtualization-type: hvm | ||
root-device-type: ebs | ||
name: 'Fedora-Cloud-Base-34-1.2.x86_64*' | ||
register: fedora_images | ||
|
||
- set_fact: | ||
image_id: '{{ fedora_images.images.0.image_id }}' | ||
vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' | ||
subnet_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/24' | ||
|
||
- name: create a VPC to work in | ||
amazon.aws.ec2_vpc_net: | ||
cidr_block: '{{ vpc_cidr }}' | ||
state: present | ||
name: '{{ resource_prefix }}_setup' | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_setup' | ||
register: setup_vpc | ||
|
||
- set_fact: | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
|
||
- name: create a subnet to use for creating an ec2 instance | ||
amazon.aws.ec2_vpc_subnet: | ||
az: '{{ aws_region }}a' | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
cidr: '{{ subnet_cidr }}' | ||
state: present | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_setup' | ||
register: setup_subnet | ||
|
||
- set_fact: | ||
subnet_id: '{{ setup_subnet.subnet.id }}' | ||
|
||
- name: create a security group to use for creating an ec2 instance | ||
ec2_security_group: | ||
name: '{{ resource_prefix }}_setup' | ||
description: 'created by Ansible integration tests' | ||
state: present | ||
vpc_id: '{{ setup_vpc.vpc.id }}' | ||
register: setup_sg | ||
|
||
- set_fact: | ||
sg_id: '{{ setup_sg.group_id }}' | ||
|
||
- name: Create ec2 instance | ||
ec2_instance: | ||
image_id: '{{ image_id }}' | ||
name: '{{ resource_prefix }}' | ||
instance_type: t2.micro | ||
security_groups: '{{ sg_id }}' | ||
vpc_subnet_id: '{{ subnet_id }}' | ||
wait: no | ||
register: setup_instance |
108 changes: 55 additions & 53 deletions
108
tests/integration/targets/inventory_aws_ec2/tasks/tear_down.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,57 @@ | ||
- ansible.builtin.set_fact: | ||
vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' | ||
subnet_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/24' | ||
|
||
- name: describe vpc | ||
ec2_vpc_net_info: | ||
filters: | ||
tag:Name: '{{ resource_prefix }}_setup' | ||
register: vpc_info | ||
|
||
- block: | ||
- name: tear down | ||
tasks: | ||
- ansible.builtin.set_fact: | ||
vpc_id: "{{ vpc_info.vpcs.0.vpc_id }}" | ||
|
||
- name: list existing instances | ||
ec2_instance_info: | ||
vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' | ||
subnet_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/24' | ||
|
||
- name: describe vpc | ||
ec2_vpc_net_info: | ||
filters: | ||
vpc-id: "{{ vpc_id }}" | ||
register: existing | ||
|
||
- name: remove ec2 instances | ||
ec2_instance: | ||
instance_ids: "{{ existing.instances | map(attribute='instance_id') | list }}" | ||
wait: yes | ||
state: absent | ||
|
||
- name: remove setup security group | ||
ec2_security_group: | ||
name: '{{ resource_prefix }}_setup' | ||
description: 'created by Ansible integration tests' | ||
state: absent | ||
vpc_id: '{{ vpc_id }}' | ||
ignore_errors: yes | ||
|
||
- name: remove setup subnet | ||
ec2_vpc_subnet: | ||
az: '{{ aws_region }}a' | ||
tags: '{{ resource_prefix }}_setup' | ||
vpc_id: '{{ vpc_id }}' | ||
cidr: '{{ subnet_cidr }}' | ||
state: absent | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_setup' | ||
ignore_errors: yes | ||
|
||
- name: remove setup VPC | ||
ec2_vpc_net: | ||
cidr_block: '{{ vpc_cidr }}' | ||
state: absent | ||
name: '{{ resource_prefix }}_setup' | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_setup' | ||
ignore_errors: yes | ||
|
||
when: vpc_info.vpcs | length > 0 | ||
tag:Name: '{{ resource_prefix }}_setup' | ||
register: vpc_info | ||
|
||
- block: | ||
- ansible.builtin.set_fact: | ||
vpc_id: "{{ vpc_info.vpcs.0.vpc_id }}" | ||
|
||
- name: list existing instances | ||
ec2_instance_info: | ||
filters: | ||
vpc-id: "{{ vpc_id }}" | ||
register: existing | ||
|
||
- name: remove ec2 instances | ||
ec2_instance: | ||
instance_ids: "{{ existing.instances | map(attribute='instance_id') | list }}" | ||
wait: yes | ||
state: absent | ||
|
||
- name: remove setup security group | ||
ec2_security_group: | ||
name: '{{ resource_prefix }}_setup' | ||
description: 'created by Ansible integration tests' | ||
state: absent | ||
vpc_id: '{{ vpc_id }}' | ||
ignore_errors: yes | ||
|
||
- name: remove setup subnet | ||
ec2_vpc_subnet: | ||
az: '{{ aws_region }}a' | ||
tags: '{{ resource_prefix }}_setup' | ||
vpc_id: '{{ vpc_id }}' | ||
cidr: '{{ subnet_cidr }}' | ||
state: absent | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_setup' | ||
ignore_errors: yes | ||
|
||
- name: remove setup VPC | ||
ec2_vpc_net: | ||
cidr_block: '{{ vpc_cidr }}' | ||
state: absent | ||
name: '{{ resource_prefix }}_setup' | ||
resource_tags: | ||
Name: '{{ resource_prefix }}_setup' | ||
ignore_errors: yes | ||
|
||
when: vpc_info.vpcs | length > 0 |
5 changes: 4 additions & 1 deletion
5
tests/integration/targets/inventory_aws_ec2/tasks/test_refresh_inventory.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters