Saturday, March 10, 2018

Playbook for installing Apache on Ubuntu - Ansible Playbook for installing Apache on Ubuntu

Please find steps for installing Apache software on nodes using Ansible in Ubuntu EC2:

1. Login to Ansible machine. Create SSH keys in Ansible host machine by executing the below command:
ssh-keygen
2. Copy the public keys(id_rsa.pub) 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/id_rsa.pub

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
[My_Group]  
34.216.41.94 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.yml
Copy the below content

---
- hosts: My_Group
  become: true
  tasks:
    - 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.yml
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 thr browser to see home page of Apache running.

1 comment: