Installing Apache in Remote hosts Using Ansible Playbook.


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 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
} | SUCCESS => {
    "changed": false, 
    "ping": "pong"
[root@ansible playbooks]#

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


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
      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: []
ok: []

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

PLAY RECAP *******************************************************************************************************************************************************************************************                 : ok=2    changed=1    unreachable=0    failed=0                : 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