Friday, March 16, 2018

Terminate EC2 Ansible Playbook Example - How to terminate EC2 using Ansible playbook

Creating EC2 instance using Ansbile on AWS is muich easier than terminating EC2. Please find a simple playbook for terminating EC2 instance using EC2 instance id.

Create playbook by executing below command:

sudo vi terminate.yml 
 - name: ec2 provisioning using Ansible
   hosts: local
   connection: local
   gather_facts: False

 - hosts: local
   gather_facts: False
   connection: local
     - region: 'us-east-2'
     - ec2_id: 'i-05f39cfb80c97df38'
     - name: Terminate instances
       local_action: ec2
         instance_ids='{{ ec2_id }}'
         region='{{ region }}'

This playbook can be executed by two ways. Either mention instance ID in the ansible playbook or pass as an argument. Intstance Id can be taken from AWS mgmt console.

ansible-playbook terminate.yml -e ec2_id=i-xxxx
PLAY [ec2 provisioning using Ansible] *********************************************************************
PLAY [local] **********************************************************************************************
TASK [Terminate instances] ********************************************************************************
ok: [local -> localhost]

PLAY RECAP ************************************************************************************************
local                      : ok=1    changed=0    unreachable=0    failed=0


  1. Great Article Cloud Computing Projects

    Networking Projects

    Final Year Projects for CSE

    JavaScript Training in Chennai

    JavaScript Training in Chennai

    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training