Day 59 of #90daysofdevops
Task
Create 3 EC2 instances. make sure all three are created with the same key pair
Install Ansible on the host server
Copy the private key from local to the Host server (Ansible_host) at (/home/ubuntu/.ssh)
access the inventory file using sudo vim /etc/ansible/hosts
Create a playbook to install Nginx
Deploy a sample webpage using the ansible-playbook
Step 1:
Create 3 instances with the same key-pair.
Step 2:
In one instance install Ansible.
Install the repository with the command: sudo apt-add-repository ppa:ansible/ansible
Update the server: sudo apt update
Install Ansible with the command: sudo apt install ansible -y
Step 3:
Copy the private key from the local to the Ansible server (Ansible - Controller) at /home/ubuntu/.ssh
Follow the command to copy: scp -i “<key pair name>” <key pair name> <public DNS of EC2>>:/home/ubuntu/.ssh
After copying, change the permissions of the file with the command: sudo chmod 600 /home/ubuntu/.ssh/ansible-master.pem
Step 4:
Add all other server's IP addresses to the "hosts" file.
Access the host file at /etc/ansible/hosts
. Make sure to use sudo.
Try to ping all the servers to verify the connections and then also update the servers.
Step 5:
Create a yaml file for the playbook to install nginx.
Run the playbook.
Step 6:
Create a webpage.
Here I have uploaded a simple responsive webpage to GitHub and I am going to clone it with git clone
command.
Now, create a playbook to upload this on other servers.
Check the IP address of other servers and verify.
Done!