Skip to content

Commit

Permalink
lint failures again
Browse files Browse the repository at this point in the history
  • Loading branch information
GomathiselviS committed Mar 3, 2023
1 parent bd6b212 commit 6780504
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 114 deletions.
121 changes: 61 additions & 60 deletions tests/integration/targets/inventory_aws_ec2/tasks/setup.yml
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 tests/integration/targets/inventory_aws_ec2/tasks/tear_down.yml
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
- name: Test updating inventory
---
- hosts: 127.0.0.1
connection: local
gather_facts: no
tasks:
- block:
- name: assert group was populated with inventory and is no longer empty
Expand Down

0 comments on commit 6780504

Please sign in to comment.