Add playbbok for create & delete pre-req. in AWS
Signed-off-by: Chandan Kumar <chandan.kr404@gmail.com>
This commit is contained in:
parent
9e07f50f5a
commit
cbb1390747
|
@ -0,0 +1,63 @@
|
|||
# delete-pre-requisite.yml
|
||||
# Description: Deleting pre requisite will delete VPC, Subnet and Internet Gateway
|
||||
|
||||
###############################################################################################
|
||||
#Test Steps:
|
||||
|
||||
#1. Disassociating route table fro aws.
|
||||
#2. Delete route table from aws.
|
||||
#3. Detach internet gateway from aws.
|
||||
#4. Delete internet gateway from aws.
|
||||
#4. Deleting the subnet from aws.
|
||||
#5. Deleting the VPC Network form aws.
|
||||
#6. Deleting temporary file which store the VpcId and SubnetId
|
||||
|
||||
###############################################################################################
|
||||
|
||||
---
|
||||
|
||||
- hosts: localhost
|
||||
|
||||
vars:
|
||||
association_id: "{{ lookup('lines', 'grep association_id /tmp/aws/id.csv | cut -d, -f5 | cut -d: -f2') }}"
|
||||
route_table_id: "{{ lookup('lines', 'grep route_table_id /tmp/aws/id.csv | cut -d, -f4 | cut -d: -f2') }}"
|
||||
gateway_id: "{{ lookup('lines', 'grep gateway_id /tmp/aws/id.csv | cut -d, -f3 | cut -d: -f2') }}"
|
||||
subnet_id: "{{ lookup('lines', 'grep subnet_id /tmp/aws/id.csv | cut -d, -f2 | cut -d: -f2') }}"
|
||||
vpc_id: "{{ lookup('lines', 'grep vpc_id /tmp/aws/id.csv | cut -d, -f1 | cut -d: -f2') }}"
|
||||
|
||||
tasks:
|
||||
- block:
|
||||
- name: Disassociating route table
|
||||
shell: aws ec2 disassociate-route-table --association-id {{ association_id }}
|
||||
ignore_errors: True
|
||||
|
||||
- name: Deleting route table
|
||||
shell: aws ec2 delete-route-table --route-table-id {{ route_table_id }}
|
||||
ignore_errors: True
|
||||
|
||||
- name: Detaching internet gateway
|
||||
shell: aws ec2 detach-internet-gateway --internet-gateway-id {{ gateway_id }} --vpc-id {{ vpc_id }}
|
||||
ignore_errors: True
|
||||
|
||||
- name: Deleting Internet gateway
|
||||
shell: aws ec2 delete-internet-gateway --internet-gateway-id {{ gateway_id }}
|
||||
ignore_errors: True
|
||||
|
||||
- name: Deleting subnet
|
||||
shell: aws ec2 delete-subnet --subnet-id {{ subnet_id }}
|
||||
ignore_errors: True
|
||||
|
||||
- name: Deleting VPC
|
||||
shell: aws ec2 delete-vpc --vpc-id {{ vpc_id }}
|
||||
|
||||
- name: Deleting tmporary file
|
||||
shell: rm /tmp/aws/id.csv
|
||||
|
||||
- name: Test Passed
|
||||
set_fact:
|
||||
flag: "Test Passed"
|
||||
|
||||
- rescue:
|
||||
- name: Test Failed
|
||||
set_fact:
|
||||
flag: "Test Failed"
|
|
@ -0,0 +1,76 @@
|
|||
# Pre-requisite.yml
|
||||
# Description: This will create VPC, Subnet and Internet gateway which is used in creating cluster
|
||||
|
||||
###############################################################################################
|
||||
#Test Steps:
|
||||
|
||||
#1. Create VPC network in aws
|
||||
#2. Modify vpc attribute
|
||||
#3. Create subnet inside the VPC Network
|
||||
#4. Create internet gateway for accessing VPC public
|
||||
#5. Attach internet gateway with VPC Network
|
||||
#6. Create route table using VpcId
|
||||
#7. Create route using route table ID
|
||||
#8. Associate route table with subnetID and route table ID
|
||||
#9. Modify subnet attribute
|
||||
#10. Create a csv file which store all Ids
|
||||
###############################################################################################
|
||||
|
||||
---
|
||||
- hosts: localhost
|
||||
|
||||
vars:
|
||||
zone: eu-west-2
|
||||
|
||||
tasks:
|
||||
- block:
|
||||
- name: create vpc in aws
|
||||
shell: aws ec2 create-vpc --cidr-block 10.0.0.0/16 | grep VpcId | cut -d ":" -f2 | cut -d '"' -f2
|
||||
register: vpc_id
|
||||
|
||||
- name: Modify vpc attribute
|
||||
shell: |
|
||||
aws ec2 modify-vpc-attribute --vpc-id {{ vpc_id.stdout }} --enable-dns-support "{\"Value\":true}"
|
||||
aws ec2 modify-vpc-attribute --vpc-id {{ vpc_id.stdout }} --enable-dns-hostnames "{\"Value\":true}"
|
||||
|
||||
- name: Creating subnet in aws
|
||||
shell: aws ec2 create-subnet --vpc-id {{ vpc_id.stdout }} --availability-zone {{ zone }}a --cidr-block 10.0.1.0/24 | grep SubnetId | cut -d ":" -f2 | cut -d '"' -f2
|
||||
register: subnet_id
|
||||
|
||||
- name: creating internet gateway
|
||||
shell: aws ec2 create-internet-gateway | grep InternetGatewayId | cut -d ":" -f2 | cut -d '"' -f2
|
||||
register: gateway_id
|
||||
|
||||
- name: Attaching internet gateway to VPC
|
||||
shell: aws ec2 attach-internet-gateway --vpc-id {{ vpc_id.stdout }} --internet-gateway-id {{ gateway_id.stdout }}
|
||||
|
||||
- name: Creating route table
|
||||
shell: aws ec2 create-route-table --vpc-id {{ vpc_id.stdout }} | grep RouteTableId | cut -d ":" -f2 | cut -d '"' -f2
|
||||
register: route_table_id
|
||||
|
||||
- name: Creating route
|
||||
shell: aws ec2 create-route --route-table-id {{ route_table_id.stdout }} --destination-cidr-block 0.0.0.0/0 --gateway-id {{ gateway_id.stdout }}
|
||||
|
||||
- name: Associating route table
|
||||
shell: aws ec2 associate-route-table --subnet-id {{ subnet_id.stdout }} --route-table-id {{ route_table_id.stdout }} | grep AssociationId | cut -d ":" -f2 | cut -d '"' -f2
|
||||
register: association_id
|
||||
|
||||
- name: Modifying subnet attribute
|
||||
shell: aws ec2 modify-subnet-attribute --subnet-id {{ subnet_id.stdout }} --map-public-ip-on-launch
|
||||
|
||||
- name: Create a csv file for store all Ids
|
||||
lineinfile:
|
||||
create: yes
|
||||
state: present
|
||||
path: "/tmp/aws/id.csv"
|
||||
line: 'vpc_id:{{ vpc_id.stdout }},subnet_id:{{ subnet_id.stdout }},gateway_id:{{ gateway_id.stdout }},route_table_id:{{ route_table_id.stdout }},association_id:{{ association_id.stdout }}'
|
||||
mode: 0755
|
||||
|
||||
- name: Test Passed
|
||||
set_fact:
|
||||
flag: "Test Passed"
|
||||
|
||||
- rescue:
|
||||
- name: Test Failed
|
||||
set_fact:
|
||||
flag: "Test Failed"
|
Loading…
Reference in New Issue