Installing Apache in Remote hosts Using Ansible Playbook.

Apache

Ansible is an open source automation tool. Which is very simple to setup and yet powerful.It can help you with task automation,configuration management,application deployment.

Ansible is available for free and runs on Linux, Mac or BSD. Aside from the free offering, Ansible also has an enterprise product called Ansible Tower.

First testing.

After installing ansible and added few hosts to the inventory file, normally /etc/ansible/hosts you can check connection between them using ping.A connection will be made with ssh keys and you can also specify a username and password.

[root@ansible playbooks]# ansible all -m ping
10.0.0.209 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
10.0.0.206 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
[root@ansible playbooks]#

Here “all” keyword is for all of the hosts in your inventory.

Playbook.

The real strength of Ansible lies in its playbooks. Playbooks are written in YAML

ansible-playbook [options] playbook.yml [playbook2 ...]

1.Creating playbook for installing httpd.

# cat httpd.. 
---
- hosts: apache
  tasks:
      name: install httpd*
      yum: name=httpd state=latest

2. Run the newly created playbook.

#ansible-playbook httpd.yaml

Which shows,

PLAY [apache] ****************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************
ok: [10.0.0.206]
ok: [10.0.0.209]

TASK [install httpd*] ********************************************************************************************************************************************************************************
changed: [10.0.0.206]
changed: [10.0.0.209]

PLAY RECAP *******************************************************************************************************************************************************************************************
10.0.0.206                 : ok=2    changed=1    unreachable=0    failed=0   
10.0.0.209                : ok=2    changed=1    unreachable=0    failed=0   

If you visit your secondary server’s hostname or IP address in your browser, you should now get apache default page