Project extends Best Songs (Static) to demonstrate using Ansible to:
- Create AWS Security Groups
- Create RDS instance, database and import sample data
- Launch, Start, Stop and Terminate EC2 instances
- Use dynamic inventory to
- Configure EC2 instances as web server and application server
- Deploy sample web application queries the RDS database and displays a random song from list of 100 songs
- AWS Account
- AWS IAM Role with Access Keys and appropriate policies attached
- Amazon EC2 Key Pairs
Open terminal window and run the following commands
sudo apt-get update
sudo apt-get install python3 python3-dev python3-pip libmysqlclient-dev mysql-client libssl-dev
pip3 install --upgrade pip
git clone https://github.com/skipluck/bestsongs-dynamic
cd bestsongs-dynamic
python3 -m venv BestSongs
source BestSongs/bin/activate
pip3 install ansible boto boto3 "pywinrm>=0.3.0" mysqlclient
chmod +x ec2.py
export AWS_ACCESS_KEY_ID='AK123'
export AWS_SECRET_ACCESS_KEY='abc123'
export ANSIBLE_NOCOWS=1
export ANSIBLE_HOST_KEY_CHECKING=false
export ANSIBLE_INVENTORY=`pwd`/ec2.py
export EC2_INI_PATH=`pwd`/ec2.ini
ansible-playbook -i localhost create_security_group.yml
ansible-playbook -i localhost create_rds.yml
ansible-playbook -i localhost create_ec2_instances.yml
Above 3 playbooks can be run at once by
ansible-playbook -i localhost create_env.yml
Note: Currently there is a bug in boto RDS module that returns TypeError and can be fixed by
body = response.read().decode('utf-8')
in rds2/layer1.py. See boto/boto#2677.
ansible-playbook -u ubuntu deploy_app.yml
deactivate