Installing LAMP in Multiple Remote Hosts Using Ansible Playbook.

Arya TM
Tensult Blogs
Published in
3 min readSep 27, 2019

This Blog has moved from Medium to blogs.tensult.com. All the latest content will be available there. Subscribe to our newsletter to stay updated.

What is Ansible?

Ansible is an open source automation tool by Michael DeHaan, which automates application deployment, intraservice orchestration, cloud provisioning and many other IT tools.

Ansible, by default manages machines over the SSH protocol. You only need to install it on one machine(Controlling Machine) and it can manage an entire fleet of remote machines(Nodes) from that controlling machine. When Ansible manages remote nodes, it does not leave software installed or running on that nodes. Ansible uses playbook to describe automation jobs, and playbook uses a very simple language called YAML

Currently Ansible can be run from any machine with Python installed (Windows isn’t supported for the control machine). This includes Red Hat, Debian, CentOS, OS X, any of the BSDs, and so on.

Configuring Controlling Machine

First check the os version of controlling machine

Os of Controlling machine

Then install ansible using corresponding package manger

First check epel repository is enabled or not

If enabled, install ansible

Then Setup Controlling Machine to connect node using ssh protocol.
Create ssh key to access node systems.

And copy the key to the nodes.

#ssh-copy-id  username@[ip of node]

Add IPs of node systems into the Inventory of Ansible by editing /etc/ansible/hosts.

Open the inventory file

Note: Here both IPs can call using name Tensult-TestNodes

First of all, test the Controlling machine’s connectivity with the node system using ansible command for ping.

#ansible -m ping [name of hosts]

Then make a directory Playbooks in side /etc/ansible. And create a yml file for writing play for installing Apache on nodes.

Then run the playbook using the below command

#ansible-playbook [name of playbook]

After successful execution of playbook check whether LAMP server is properly installed on nodes by running the following command on controlling machine.

#ansible Tensult-lampnodes -a "httpd -v"
#ansible Tensult-lampnodes -a "php -v"
#ansible Tensult-lampnodes -a "mysql -V"

Conclusion

Hence, we have successfully installed lamp server on multiple nodes with single execution of script. Likewise we can automate simple to complex operation using automation tools. There are lots of other automation tools available nowadays which makes tasks much easier. Feel free to post your comments.

--

--