— Anna Dowling 2018/06/08 07:38
Bitbucket Repo: https://bitbucket.org/errigal/ansible-aws/
Other Available SDK's for AWS: https://aws.amazon.com/tools/
The Following things need to be installed on your local machine prior to using this project
There are a number of ways to run ansible scripts against aws. The method chosen for this project was to package the credentials within the environment variables. As we have multiple AWS accounts currently, we also have multiple environments set up in the project (qaatc, nvqa). These each have a vault file containing the access key and secret key for that account. These are fully encrypted and require a password to run all scripts. Passwords can be found in PasswordSafe under AWS ANSIBLE VAULT ENVIRONMENTS.
Due to dependencies of certain things being created at certain stages, the following is the ordering in which to run the creation and deletion playbooks associated with this project.
Restore an RDS Instance from a snapshot and adds a route 53 entry for that rds instance to resolve the host name to its rds endpoint.
Command line Parameters:
ansible-playbook createRDSInstance.yml -e "env=NAME_OF_AWS_ENV rds_snapshot=rds:atc-rds-instance-snapshot-name add_route53='true'" --ask-vault-pass
Delete an RDS instance from a specified name.
Command line Parameters:
ansible-playbook deleteRDSInstance.yml -e "env=NAME_OF_AWS_ENV rds_instance_name=rds:atc-rds-instance-name-to-delete" --ask-vault-pass
Create an EC2 Instances inside a vpc assigned to a subnet group.
Command line Parameters:
Command LB1: ansible-playbook -i local createEC2Instance.yml -e "env=NAME_OF_AWS_ENV volume_size=55 instance_type=r3.large region=us-east-1 count=1 subnet_id=subnet-2660a37a ami=ami-6468041b name=qa_atc_lb1 keypair=atc-prod private_ip=10.91.202.197 add_elasticip='true'" --ask-vault-pass Command APPS1: ansible-playbook -i local createEC2Instance.yml -e "env=NAME_OF_AWS_ENV volume_size=55 instance_type=r3.xlarge region=us-east-1 count=1 subnet_id=subnet-2660a37a ami=ami-19690566 name=qa_atc_apps1 keypair=atc-prod private_ip=10.91.202.198 add_elasticip='true'" --ask-vault-pass Command APPS2: ansible-playbook -i local createEC2Instance.yml -e "env=NAME_OF_AWS_ENV volume_size=55 instance_type=r3.xlarge region=us-east-1 count=1 subnet_id=subnet-2660a37a ami=ami-126a066d name=qa_atc_apps2 keypair=atc-prod private_ip=10.91.202.199 add_elasticip='true'" --ask-vault-pass
Delete an EC2 Instances by specifying its id.
Command line Parameters:
ansible-playbook deleteEC2Instance.yml -e "env=NAME_OF_AWS_ENV specified_instance_id='ID-OF-EC2-INSTANCE-TO-DELETE'" --ask-vault-pass
Reboot an EC2 Instances by specifying its id.
Command line Parameters:
ansible-playbook rebootEC2.yml -e "env=NAME_OF_AWS_ENV specified_instance_id='ID-OF-INSTANCE-TO-REBOOT'" --ask-vault-pass
Create Application Load Balancer, assign the SSL Certificate from its ARN id (the cert should be uploaded to AWS prior to this) and Assign Target Group forwarding Rules to the ALB.
ansible-playbook -e "env=NAME_OF_AWS_ENV" createALBAndAssignRules.yml --ask-vault-pass
Delete the Application Load Balancer(name is specified in the group_vars for the appropriate environment). This deletion step must be run before deleting the target groups.
ansible-playbook -e "env=NAME_OF_AWS_ENV" deleteALB.yml --ask-vault-pass
https://docs.ansible.com/ansible/2.5/modules/elb_target_group_module.html?highlight=elb_target_group
Create Application Load Balancer Target Groups for Applications and EC2 Handlers to forward traffic for different apps between the correct handlers and distribute load.
ansible-playbook -e "env=NAME_OF_AWS_ENV" createTargetGroup.yml --ask-vault-pass
Deletes application load balancer target groups.
ansible-playbook -e "env=NAME_OF_AWS_ENV" deleteTargetGroup.yml --ask-vault-pass
Repository url: https://bitbucket.org/errigal/env-snapshot-manager/src This project covers all the playbooks needed in order to automate the volume snapshot process for our AWS EC2 servers. This provides us with a means of failover for server storage if a recovery scenario was needed.
Details: - Runs on NVQALB1 & ATCLB1 currently - Permissions to run this ansible script are handled through IAM role assignments on the instance so no API keys are stored for security reasons. This also allevaited the problem of not being able to use a password with the cronjob.
## Scheduling The process is be scheduled to run via cron using the create_ec2_snapshots.sh file (ensure this file is executable using chmod +x) The correct environment playbook should be specified in the bash script ansible command (i.e. nvqa, atcprod). The tag options for create and deleting snapshots must be set to true in order for the process to work.
ansible-playbook playbooks/nvqa/ec2-snapshot.yml $TAGS_OPTION -e"name=standalone_name_server del_snapshot='true' add_snapshot='true'" --verbose 01 00 * * * /export/home/scotty/env-snapshot-manager/create_ec2_snapshots.sh