Ansible playbook that takes AWS RDS, EFS (using AWS Backup), EC2 snapshots and application(ex. Neo4j DB on Ubuntu EC2 instance) backup in parallel
This is a sample Ansible playbook solution that executes below flow :
-
Dependencies : For this solution, it is assumed that the Bastian host has necessary dependencies installed like Ansible, Boto (to execute AWS operations), etc. More info on AWS Linux Bastian host
-
Ansible operations from playbooks : Ansible supported AWS modules
For other AWS operations, AWS CLI is used. Configuring the AWS CLI
-
SSH key of the <my_app> EC2 instance is copied from S3 bucket into Bastian host to perform SSH operations.
-
AWS constants : Some variables for AWS operations like region, account_id are stored as constants in vars files. This could to be enhanced to be dynamic.
-
Pre and post scripts : As pre-script, httpd service is stopped and as post-script, httpd service is started. This could be enhanced to run any scripts.
-
This sample solution doesn't include automated/scheduled backup option. It can be enhanced as needed.
The inventories section contains the hosts information [Bastian host + <my_app> EC2 instances].
It also includes common variables (like AWS region, account_id etc.) across all hosts and roles that are used for executing AWS operations.
The playbook is divided into roles as shown in above tree structure.
Each role has its own vars (can be changed as needed) and tasks directories mentioning the operations to be performed by that role.
NOTE : Running these playbooks uses AWS services and creates Backup resources, which could add cost as per AWS pricing.
-
Clone this repository :
git clone https://github.com/sanket-bengali/aws-backup-ansible.git
-
Go to the playbook directory :
cd /path/to/repository/ansible/aws/
-
Update inventory files variables
In "inventories/poc/hosts" : <ec2_public_ip>, <ec2_user>, <neo4j_ec2_public_ip>
In "inventories/poc/group_vars/all.yaml" : "aws-region", "aws-account-id"
-
Update playbooks variables inside "roles"
a. get_ssh_key
-> In "get_ssh_key/tasks/main.yaml" : <bucket_name>, <path_to_ssh_key/key_name.pem>
-> In "get_ssh_key/vars/main.yaml" : <key_name.pem>
b. take_ec2_snapshot
-> In "take_ec2_snapshot/vars/main.yaml" : "my-app-ec2-instance-name", "ec2_device_name"
c. take_efs_backup
-> In "take_efs_backup/vars/main.yaml" : "my-app-efs-name", "efs-backup-vault-name"
d. take_rds_snapshot
-> In "take_rds_snapshot/vars/main.yaml" : "my-app-pgsql-db"
e. take_neo4j_db_backup
-> In "take_neo4j_db_backup/vars/main.yaml" : "/home/ubuntu/<neo4j_backup_dir>"
-
Run the playbook :
ansible-playbook my_app_backup.yaml -i inventories/poc/hosts
AWS services backup using Ansible playbooks
The MIT License (MIT). Please see License File for more information.