mikhailadvani.ec2-start-stop

ec2-start-stop

This role is designed to start or stop EC2 instances and optionally associate or disassociate Elastic IP addresses.

Requirements

  • Python 2.7
  • Boto library
  • AWS access keys with EC2FullAccess permissions

Role Variables

  • AWS_ACCESS_KEY_ID: Your access key with EC2FullAccess permissions. Set as an environment variable.
  • AWS_SECRET_ACCESS_KEY: The secret access key corresponding to your AWS_ACCESS_KEY_ID.
  • EC2_REGION: The region where your AWS resources are located.
  • action: Specify whether to start or stop the instance(s). Default: start.
  • reuse_existing_ip_allowed: Set to yes or no to allow reusing unassociated IPs allocated to your account. Default: yes.
  • release_on_disassociation: Set to yes or no to release the IP when disassociating. Default: yes.
  • roles_directory: The folder where the role is located. Default: roles.
  • instances.tags: The tags for the instance(s) you want to start or stop.
  • instances.elastic_ip: Set to yes or no to indicate if you want to associate an Elastic IP. It will be associated during start and disassociated during stop. Reuse and release behavior depends on reuse_existing_ip_allowed and release_on_disassociation.

Example Playbook

To start an instance:

ansible-playbook ec2-start-stop.yml -e "action=start reuse_existing_ip_allowed=yes"

To stop an instance:

ansible-playbook ec2-start-stop.yml -e "action=stop release_on_disassociation=no"

Here’s a sample playbook structure:

- hosts: localhost
  connection: local
  environment:
    AWS_ACCESS_KEY_ID: "{{AWS_ACCESS_KEY_ID}}"
    AWS_SECRET_ACCESS_KEY: "{{AWS_SECRET_ACCESS_KEY}}"
    EC2_REGION: "{{EC2_REGION}}"
  roles:
    - {role: ec2-start-stop}

License

MIT License

Author Information

This role was created in 2016 by Mikhail Advani.

Twitter: @mikhail_advani

Informazioni sul progetto

Start stop EC2 instances with optional association/disassociation of elastic IPs

Installa
ansible-galaxy install mikhailadvani.ec2-start-stop
Licenza
mit
Download
74
Proprietario