Friday, August 6, 2021

Ansible playbook to install Apache on Ubuntu | How to install Apache Using Ansible on Ubuntu 22.0.4

Find the playbook for installing Apache on Ubuntu using Ansible:

Click here if you would like learn how to create a new Ubuntu EC2 instance using Ansible Playbook.


Setup Ansible on EC2 instance with Boto.

Install Apache using Ansible Playbook

1. Login to Ansible machine. Create SSH keys in Ansible host machine by executing the below command:

2. Copy the public keys( from ansible node each node in /home/ubuntu/.ssh/authorized_keys file. Execute the below command on Ansible and copy the content:
 sudo cat ~/.ssh/

3. Now login to target node, execute the below command to open the file
sudo vi /home/ubuntu/.ssh/authorized_keys
type shift A and then enter. now 
    and paste the key in the above file. please do not delete any existing keys.

4. go back to ansible mgmt node, make sure you are able to ssh from ansible mgmt node after copying the keys above:
ssh private_ip_of_target_node
now type exit to come out of the target node.

5. Now in ansible mgmt node, now make changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public IP address as highlighted below in green color:
sudo vi /etc/ansible/hosts
XX.XX.XX.XX ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

6. make changes in playbooks as given below,
cd ~/playbooks

sudo vi installApache.xml
Copy the below content

- hosts: Apache_Group
  become: true
    - name: Install apcahe
      apt: name=apache2 state=present update_cache=yes

    - name: ensure apache started
      service: name=apache2 state=started enabled=yes

7. now execute the playbook by running the below command:
sudo ansible-playbook installApache.xml
8. This should install Apache on the nodes and should bring the apache up and running.
9. Now enter public ip address or public dns name of target server by in the browser to see home page of Apache running.

Please watch this step on YouTube channel:

No comments:

Post a Comment

How to create Pull Request (PR) templates in Github repository | Creating a pull request template for your GitHub repository

Creating pull request (PR) templates in GitHub can help streamline the process of submitting PRs by providing a predefined structure. Thi...