This code is tested on the AWS ubuntu machine.
- Anisble Server - EC2 Ubuntu Instance (Ansible should be installed)
- PHP Server - EC2 Ubuntu Instance
- All variables are declared under
group_vars/all.yaml
- Update inventory file
inventories/dev/hosts
- Generate the public key for the user ubuntu
ssh-keygen
on Ansible Server - Copy the
id_rsa.pub
fromcd ~./ssh
and paste it on the PHP Servervi ~/.ssh/authorized_keys
or you can use the priavte key and run this playbook which will automatically copy the public key on the target hosts
- Copy the private key on the ansible server
chmod 600 exam-project.pem
scp -r -i /Users/DMCPaviliondv6/Documents/devops4solutions/AWS/exam-project.pem /Users/DMCPaviliondv6/Documents/devops4solutions/AWS/exam-project.pem ubuntu@18.219.xxx.xxx:~/.
cd Ansible-playbook
ansible-playbook main.yml -i inventories/dev/hosts --user ubuntu --key-file /home/ubuntu/exam-project.pem
Make sure security group of AWS EC2 ansible-slave Server is open for port 80.
curl http://publicip