Skip to content

Commit

Permalink
Add destroy.yml for examples/alicloud_ecs_vpc
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhu36 committed Oct 24, 2018
1 parent 1669689 commit 45db990
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

IMPROVEMENTS:

- Add destroy.yml for examples/alicloud_ecs_vpc ([#117](https://github.com/alibaba/ansible-provider/pull/117))
- Improve roles test cases ([#116](https://github.com/alibaba/ansible-provider/pull/116))
- Improve example/alicloud-ecs-vpc ([#114](https://github.com/alibaba/ansible-provider/pull/114), [#115](https://github.com/alibaba/ansible-provider/pull/115))
- Change nested_groups default to False ([#113](https://github.com/alibaba/ansible-provider/pull/113git ))
Expand Down
93 changes: 93 additions & 0 deletions examples/alicloud-ecs-vpc/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
- name: Create an alicloud vpc cluster using ansible-provider-alicloud
hosts: localhost
remote_user: root

tasks:
- name: Get the existing instances
ali_instance_facts:
alicloud_region: '{{ alicloud_region }}'
alicloud_zone: '{{ alicloud_zone }}'
instance_names:
- '{{ instance_name }}'
register: instances

- name: Delete the existing instances
ali_instance:
alicloud_region: '{{ alicloud_region }}'
alicloud_zone: '{{ alicloud_zone }}'
instance_ids:
- '{{ instances.instances.0.id }}'
- '{{ instances.instances.1.id }}'
force: true
state: absent
when: instances.instances

- name: Get the existing disks
ali_disk_facts:
alicloud_region: '{{ alicloud_region }}'
alicloud_zone: '{{ alicloud_zone }}'
disk_names:
- '{{ disk_name }}-0'
- '{{ disk_name }}-1'
register: disks

- name: Delete the existing disk 0
ali_disk:
alicloud_region: '{{ alicloud_region }}'
alicloud_zone: '{{ alicloud_zone }}'
disk_id: '{{ disks.disks.0.id }}'
state: absent
when: disks.disks

- name: Delete the existing disk 1
ali_disk:
alicloud_region: '{{ alicloud_region }}'
alicloud_zone: '{{ alicloud_zone }}'
disk_id: '{{ disks.disks.1.id}}'
state: absent
when: disks.disks

- name: Get the existing vpc
ali_vpc_facts:
region: '{{alicloud_region}}'
vpc_name: '{{vpc_name}}'
register: vpcs

- name: Get the existing groups
ali_security_group_facts:
region: '{{alicloud_region}}'
filters:
vpc_id: '{{vpcs.vpcs.0.id}}'
when: vpcs.vpcs
register: sgs

- name: Delete the existing security groups
ali_security_group:
alicloud_region: '{{ alicloud_region }}'
group_id: '{{ sgs.groups.0.id}}'
state: absent
when: sgs.groups

- name: Get the existing vswitches
ali_vswitch_facts:
region: '{{alicloud_region}}'
filters:
vpc_id: '{{vpcs.vpcs.0.id}}'
when: vpcs.vpcs
register: vsws

- name: Delete the existing vswitch
ali_vswitch:
alicloud_region: '{{ alicloud_region }}'
alicloud_zone: '{{ alicloud_zone }}'
vswitch_id: '{{ vsws.vswitches.0.id }}'
state: absent
when: vsws.vswitches

- name: Delete the existing vpc
ali_vpc:
alicloud_region: '{{ alicloud_region }}'
vpc_id: '{{ vpcs.vpcs.0.id}}'
state: absent
when: vpcs.vpcs

0 comments on commit 45db990

Please sign in to comment.