Added workflow to delete cloud stack

This commit is contained in:
Chris Edillon
2025-06-24 21:53:41 -04:00
parent 0634643f21
commit 605aa91080
4 changed files with 231 additions and 1 deletions

View File

@@ -27,7 +27,7 @@
- us-east-2b
- us-east-2c
us-west-1:
# us-west-1a not available when last checked 20250218
# us-west-1a not available when last checked 20250618
- us-west-1b
- us-west-1c
us-west-2:

22
cloud/delete_aws_key.yml Normal file
View File

@@ -0,0 +1,22 @@
---
- name: Delete AWS keypair
hosts: localhost
vars:
aws_key_name: aws-test-key
tasks:
- name: Fail if variables not defined
ansible.builtin.assert:
that:
- aws_key_name is defined
- create_vm_aws_region is defined
fail_msg: "Required variables not set"
- name: Delete AWS keypair
amazon.aws.ec2_key:
name: "{{ aws_key_name }}"
region: "{{ create_vm_aws_region }}"
state: absent
...

83
cloud/delete_vpc.yml Normal file
View File

@@ -0,0 +1,83 @@
---
- name: Delete cloud stack VPC
hosts: localhost
gather_facts: false
vars:
aws_vpc_name: aws-test-vpc
aws_sg_name: aws-test-sg
aws_subnet_name: aws-test-subnet
aws_subnet_cidr: 10.0.1.0/24
aws_rt_name: aws-test-rt
aws_purpose_tag: ansible_demo
tasks:
- name: Verify the VPC name
ansible.builtin.assert:
that:
- aws_vpc_name == "aws-test-vpc"
fail_msg: 'Only the VPC "aws-test-vpc" can be deleted with this playbook'
- name: Retrieve VPC info
amazon.aws.ec2_vpc_net_info:
region: "{{ create_vm_aws_region }}"
filters:
"tag:Name": "{{ aws_vpc_name }}"
"tag:purpose": "{{ aws_purpose_tag }}"
register: _vpc
- name: Retrieve internet gateway info
amazon.aws.ec2_vpc_igw_info:
region: "{{ create_vm_aws_region }}"
filters:
"tag:Name": "{{ aws_vpc_name }}"
"tag:purpose": "{{ aws_purpose_tag }}"
register: _igw
- name: Retrieve route table info
amazon.aws.ec2_vpc_route_table_info:
region: "{{ create_vm_aws_region }}"
filters:
"tag:Name": "{{ aws_rt_name }}"
"tag:purpose": "{{ aws_purpose_tag }}"
register: _rt
- name: Delete demo security group
amazon.aws.ec2_security_group:
name: "{{ aws_sg_name }}"
region: "{{ create_vm_aws_region }}"
vpc_id: "{{ _vpc.vpcs.0.id }}"
state: absent
when: _vpc.vpcs
- name: Delete subnet in the VPC
amazon.aws.ec2_vpc_subnet:
vpc_id: "{{ _vpc.vpcs.0.id }}"
cidr: "{{ aws_subnet_cidr }}"
region: "{{ create_vm_aws_region }}"
state: absent
when: _vpc.vpcs
- name: Delete the subnet route table
amazon.aws.ec2_vpc_route_table:
route_table_id: "{{ _rt.route_tables.0.route_table_id }}"
region: "{{ create_vm_aws_region }}"
lookup: id
state: absent
when: _rt.route_tables
- name: Delete internet gateway
amazon.aws.ec2_vpc_igw:
internet_gateway_id: "{{ _igw.internet_gateways.0.internet_gateway_id }}"
region: "{{ create_vm_aws_region }}"
state: absent
when: _igw.internet_gateways
- name: Delete VPC
amazon.aws.ec2_vpc_net:
vpc_id: "{{ _vpc.vpcs.0.id }}"
region: "{{ create_vm_aws_region }}"
state: absent
when: _vpc.vpcs
...

View File

@@ -171,6 +171,63 @@ controller_templates:
variable: _hosts
required: false
- name: Cloud / AWS / Delete Keypair
job_type: run
organization: Default
credentials:
- AWS
project: Ansible Product Demos
playbook: cloud/delete_aws_key.yml
inventory: Demo Inventory
notification_templates_started: Telemetry
notification_templates_success: Telemetry
notification_templates_error: Telemetry
survey_enabled: true
survey:
name: ''
description: ''
spec:
- question_name: AWS Region
type: multiplechoice
variable: create_vm_aws_region
required: true
choices:
- us-east-1
- us-east-2
- us-west-1
- us-west-2
- question_name: Keypair Name
type: text
variable: aws_key_name
required: true
default: aws-test-key
- name: Cloud / AWS / Delete VPC
job_type: run
organization: Default
credentials:
- AWS
project: Ansible Product Demos
playbook: cloud/delete_vpc.yml
inventory: Demo Inventory
notification_templates_started: Telemetry
notification_templates_success: Telemetry
notification_templates_error: Telemetry
survey_enabled: true
survey:
name: ''
description: ''
spec:
- question_name: AWS Region
type: multiplechoice
variable: create_vm_aws_region
required: true
choices:
- us-east-1
- us-east-2
- us-west-1
- us-west-2
- name: Cloud / AWS / Display EC2 Stats
job_type: run
organization: Default
@@ -392,3 +449,71 @@ controller_workflows:
unified_job_template: 'SUBMIT FEEDBACK'
extra_data:
feedback: Cloud / AWS / Patch EC2 Workflow | Failed to restore ec2 from snapshot
- name: Delete AWS Cloud Stack
description: >
Delete the AWS cloud stack created by the "Deploy Cloud Stack in AWS" workflow
organization: Default
notification_templates_started: Telemetry
notification_templates_success: Telemetry
notification_templates_error: Telemetry
survey_enabled: true
survey:
name: ''
description: ''
spec:
- question_name: AWS Region
type: multiplechoice
variable: create_vm_aws_region
required: true
choices:
- us-east-1
- us-east-2
- us-west-1
- us-west-2
- question_name: Instances to delete
type: text
variable: _hosts
required: true
default: aws-dc,aws_win1,aws_rhel8,aws_rhel9,reports
- question_name: Keypair to delete
type: text
variable: aws_key_name
required: true
default: aws-test-key
- question_name: VPC to delete
type: text
variable: aws_vpc_name
required: true
default: aws-test-vpc
simplified_workflow_nodes:
- identifier: Delete AWS Instances
unified_job_template: Cloud / AWS / Delete VM
success_nodes:
- Delete AWS Keypair
failure_nodes:
- Ticket - Delete AWS Instances Failed
- identifier: Delete AWS Keypair
unified_job_template: Cloud / AWS / Delete Keypair
success_nodes:
- Delete AWS VPC
failure_nodes:
- Ticket - Delete AWS Keypair Failed
- identifier: Ticket - Delete AWS Instances Failed
unified_job_template: 'SUBMIT FEEDBACK'
extra_data:
feedback: Failed to delete one or more AWS instances
- identifier: Ticket - Delete AWS Keypair Failed
unified_job_template: 'SUBMIT FEEDBACK'
extra_data:
feedback: Failed to delete AWS keypair
- identifier: Delete AWS VPC
unified_job_template: Cloud / AWS / Delete VPC
failure_nodes:
- Ticket - Delete AWS VPC Failed
- identifier: Ticket - Delete AWS VPC Failed
unified_job_template: 'SUBMIT FEEDBACK'
extra_data:
feedback: Failed to delete AWS VPC
...