Ansible using Python3
$sudo pip3 install ansible
Install boto and boto3
$sudo pip3 install boto
$sudo pip3 install boto3
You need to create the file ~/.aws/credentials or set aws_secret_access_key and aws_access_key_id
The project is divided in two playbooks that calls task in the folder task/
The first playbook that must to be deployed to create the infrastructure from the application is main.yml
The main.yml playbook import tasks network.yml, rds.yml and instances.yml
network.yml - Must be deployed first at all. This task will create all network enviromment on aws(VPC,SG, LB, IGW) and create the infonetwork.json the save necessary network information to other deploy without the need to run it again.
rds.yml - It will create the subnet_group to RDS and the RDS instance. Get credentials from ./files/credentials.json that must to be set before run the playbook.
instances.yml - This playbook generete the key pair to access the ec2 instance and create the VM, also add the instance to host.txt file(if not exist, it will be created) and save the access key if does not exist.
The application's playbook is deploy_app.yml that import the installreq.yml, createdb.yml and app.ymlinstallreq.ym - This task install all dependences that the application require.
createdb.ym - Create the database "demo" on RDS. This task can only be deployed from the VM because there is no external access to RDS.
app.yml - This is the task that run the application flask.
To run the playbooks is just need to add a password on files/credentials.json and run the commands below:
ansible-playbook main.yml
ansible-playbook -i host.txt deploy_app.yml