HOW TO INSTALL LAMP ON A REMOTE SERVER USING ANSIBLE PLAYBOOK

About

An Ansible Playbook is an organized unit of scripts that defines work for a server configuration managed by ansible. Ansible Playbooks are written in YAML. An Ansible playbook contains one or more plays, each of which define the work to be done for a configuration on a managed server or group of servers.

Here I will show you how to install LAMP on a remote Ubuntu machine.

Create a directory to store your playbooks:

#mkdir playbooks

Enter into the directory:

#cd playbooks

Then create a new yaml file to write the LAMP installation script, and open the file:

#vi lamp.yaml

A yaml file always starts with three hyphens (- – -)

– – –

Then you have to specify the hosts on which you are going to install LAMP:

– hosts: sfcgroup

Now we are going to add the tasks:

 tasks:

Script to install Apache2:

  – name: Installing package Apache2

     apt: pkg=apache2 state=present

     become: true

Then start the Apache service:

  – name: Start Apache

     service: name=apache2 state=started enabled=true

     become: true

Script to install the mysql:

  – name: Installing mysql-server

     apt: pkg=mysql-server state=present

     become: true

Then Start the the mysql service:

name: Start Mysql
service: name=mysql state=started enabled=true
become: true


Script to install PHP

name: Installing php7.0
apt: pkg=php7.0 state=present
become: true


Script to install PHP module for Apache

name: Installing PHP module for Apache2
apt: pkg=libapache2-mod-php7.0 state=present
become: true


Script to install PHP module for Mysql

name: Installing PHP module for Mysql
apt: pkg=php7.0-mysql state=present
become: true


Install additional cURL, JSON, and CGI support (Optional):

name: Installing cURL
apt: pkg=php7.0-curl state=present
become: true

name: Installing JSON
apt: pkg=php7.0-json state=present
become: true

name: Installing CGI
apt: pkg=php7.0-cgi state=present
become: true


The entire yaml file will be look like the image below:

To install LAMP on the hosts just type the command given below:

#ansible-playbook lamp.yaml

The output will be as below:

That’s all!

Leave a Reply

Your email address will not be published. Required fields are marked *