Day 59: Ansible Project πŸ”₯

Day 59: Ansible Project πŸ”₯

Ansible playbooks are amazing, as you learned yesterday. What if you deploy a simple web app using ansible, sounds like a good project, right?

Task-01

  • Install Ansible in host server.
  1. Launch an EC2 instance. Enter desired name, make a new key pair.

2. Your instance will be created. Connect to your newly made instance via EC2 connect or SSH.

3. Fire the command β€œsudo apt-add-repository ppa:ansible/ansible”.

4. Run the command β€œsudo apt update”.

5. Run the command β€œsudo apt install ansible”.

6. Run β€œcat /etc/ansible/hosts” to check whether ansible is installed or not.

  • Create 3 EC2 instances . make sure all three are created with same key pair

  • Copy the private key from local to Host server (Ansible_host) at (/home/ubuntu/.ssh).

  1. Launch 3 more instances. Use the key-pair which was made earlier for Ansible Master instance.

2. Your instances will be launched.

  • Copy the private key to master server where Ansible is setup.
  1. Fire command β€œsudo vim /etc/ansible/hosts”.

2. Add IP of the servers which you have created.

3. Fire the command β€œansible servers -m ping” to connect to servers. Here β€œservers” is the group name which you have given in /etc/ansible/hosts file. Error will come because you have not given public key to connect to servers.

4. Run command β€œcd .ssh” and then β€œpwd”. Copy the path.

5. Connect to ansible master instance via Powershell via SSH. Fire the command β€œscp ssh -i β€œAnsible-Master-New.pem” Ansible-Master-New.pem ubuntu@ec2–3–237–179–91.compute-1.amazonaws.com:<path of .ssh directory>”

Note:- Ansible-Master-New.pem is to be given 2 times here as above.

6. Go back and do β€œls”. Your key will be visible.

7. Again fire command β€œsudo vim /etc/ansible/hosts” and add the given below configurations.

8. Do β€œcd .ssh” and run command β€œchmod 600 <key_name>” to give permissions to your key.

  • Try a ping command using ansible to the Nodes.

Fire command β€œansible servers -m ping”.

  • Access the inventory file using sudo vim /etc/ansible/hosts.

Fire command β€œsudo vim /etc/ansible/hosts” and add the given below configurations.

  • Create a playbook to install Nginx.
  1. Fire the command β€œvim install_nginx.yml” and add given below configurations in it for creating a new file.

2. Run the command β€œansible-playbook <file_name.yml>”.

3. Go to your servers to check whether file has been created or not.

  • Deploy a sample webpage using the ansible playbook.
  1. Make a file by using command β€œvim index.html” which will contain source code of the webpage to be hosted.

2. Fire the command β€œvim webpage.yml” and add given below configurations in it for creating a new file.

3. Run the command β€œansible-playbook <file_name.yml>”.

4. Go to your servers to check whether webpage has been hosted or not.

Β