Skip to content

Latest commit

 

History

History
106 lines (63 loc) · 5.23 KB

README.md

File metadata and controls

106 lines (63 loc) · 5.23 KB

AWS EC2 Operational Tasks

This Ansible Project showcase multiple AWS (Amazon Web Services) operational tasks fully automated with Ansible Playbooks.

An operational tasks is a routine task an operator (cloud administer) has to do outside of provisioning and deprovisioning resources. Declarative automation (such as AWS CloudFormation templates) are great until someone manually, or some tool outside of CloudFormation starts interacting with the public cloud. There is always use cases for imperative repeatable tasks that operators are doing manually.

Table of Contents

Glossary of AWS terms

ec2 - Amazon Elastic Compute Cloud, Secure, resizable compute capacity in the cloud.

ec2 region - Amazon cloud computing resources are hosted in multiple locations world-wide. These locations are composed of AWS Regions, Availability Zones, and Local Zones. Each AWS Region is a separate geographic area. Each AWS Region has multiple, isolated locations known as Availability Zones. read more here

ec2 instance - Any compute deployment within the Amazon EC2 service.

tag - metadata for AWS resources. Each tag is a simple label consisting of a customer-defined key and an optional value that can make it easier to manage, search for, and filter resources by purpose, owner, environment, or other criteria. AWS tags can be used for many purposes.

Ansible Playbook Examples

Retrieve and Stop

playbooks/stop_instances.yaml link

ansible-playbook stop_instances.yaml -e "your_region=us-west-1"

This Ansible Playbook will retrieve all instances from the specified region us-west-1 and stop them.

Turn long-running instances off

playbooks/turn_off_time.yaml link

ansible-playbook turn_off_time.yaml -e "your_region=us-west-1 kill_time=100"

This Ansible Playbook will retrieve all instances from the specified region us-west-1 that have been running over 100 minutes, then stop them.

Turn untagged instances off

playbooks/no_tags.yaml link

ansible-playbook no_tags.yaml -e "your_region=us-west-1"

This Ansible Playbook will retrieve all instances from the specified region us-west-1 that have no tags, and stop them. No tags means literally they have zero tags, not a single tag. It is not looking for a specific tag.

Retrieve instances without a specific tag

playbooks/missing_tag.yaml link

ansible-playbook missing_tag.yaml -e "your_region=us-west-1"

This Ansible Playbook will retrieve all instances from the specified region us-west-1 that don't have the specific tag key owner (e.g. tags.owner). This allows an operator to enforce a specific tag (e.g. assign an owner to each resource in this example) or it will be scheduled in Ansible Automation Platform to be turned off.

Put instances to sleep

playbooks/sleep_schedule_off.yaml link

ansible-playbook sleep_schedule_off.yaml -e "your_region=us-west-1"

This Ansible Playbook will retrieve all instances from the specified region us-west-1 that have the specific tag key pair sleep_schedule: true. This allows operators to optionally add a tag to their instances, to turn them off at night. This Ansible Playbook would be scheduled in Ansible Automation Platform to run every evening at a specific time. In a multi-region scenario this could be enhanced with timezones to allow operators to specify their timezone or working hours.

Wake up sleepy instances

playbooks/sleep_schedule_on.yaml link

ansible-playbook sleep_schedule_on.yaml -e "your_region=us-west-1"

This Ansible Playbook will retrieve all instances from the specified region us-west-1 that have the specific tag key pair sleep_schedule: true. This allows operators to optionally add a tag to their instances, to turn them on in the morning (opposite of previous example, please see above for more information).

Ansible Demos

ansible demo logo

This project is maintained by Red Hat.