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.
- 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).
- 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.
- 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.
- 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.
- 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.