Commit a6d8da22 by Brian Beggs

Cleanup playbook to be used in the continuous delivery pipeline

parent 6d8f3007
# This playbook will clean up the work done in the create_ami and launch_instance playbooks consisting of the following work:
# - delete the key used to bring up the instance
# - terminate the instance used to create the AMI
# - delete the ansible-runtime/<run identifer directory>
#
# Required variables for this playbook:
#
# - instance_id - the ec2 instance ID use to create the AMI
# - keypair_id - the keypair used to launch the instance.
#
# Other variables
# - ec2_region - The region used to create the AMI
# - hipchat_token - API token to send messages to hipchat
# - hipchat_room - ID or name of the room to send the notification
# - hipchat_url - URL of the hipchat API (defaults to v1 of the api)
#
# Example command line to run this playbook:
# ansible-playbook -vvvv -i "localhost," -c local \
# -e @overrides.yml \
# -e @/tmp/ansible-runtime/d057a5d9-4fc5-4a21-9646-4c135be0b7c8/launch_info.yml \
# cleanup.yml
#
- hosts: all
vars:
ec2_region: us-east-1
ec2_timeout: 300
artifact_path: /tmp/ansible-runtime
hipchat_url: https://api.hipchat.com/v2/
gather_facts: False
connection: local
tasks:
- name: Delete keypair
ec2_key:
state: absent
region: "{{ ec2_region }}"
name: "{{ keypair_id }}"
- name: Terminate Instance
ec2:
region: "{{ ec2_region }}"
state: absent
instance_ids: "{{ instance_id }}"
- name: cleanup local file system
file:
path: "{{ artifact_path }}/{{ keypair_id }}"
state: absent
- name: Send Hipchat notification cleanup has finished
hipchat:
api: "{{ hipchat_url }}"
token: "{{ hipchat_token }}"
room: "{{ hipchat_room }}"
msg: "Cleanup for run id: {{ keypair_id }} complete."
when: hipchat_token is defined
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment