Project Exam Summary: Automatically provision multiVMs (2 - master & slave), create bash script to deploy LAMP Stack on master vm/node, use Ansible to execute the bash script on slave vm/node.
- Automate the provisioning of two Ubuntu-based servers, named “Master” and “Slave”, using Vagrant.
- On the Master node, create a bash script to automate the deployment of a LAMP (Linux, Apache, MySQL, PHP) stack.
- This script should clone a Laravel PHP application from GitHub, install all necessary packages, and configure Apache web server and MySQL.
- Ensure the bash script is reusable and readable.
- Using an Ansible playbook:
- Execute the bash script on the Slave node and verify that the PHP application is accessible through the VM’s IP address (take screenshot of this as evidence).
- Create a cron job to check the server’s uptime every 12 am.
Defined two VMs in Vagrantfile, namely 'master' and 'slave', and assigned two static IPs to them; master - 192.168.56.10, slave - 192.168.56.11.
Vagrant up both VMs and checked the IP address for proof.
Master VM - 192.168.56.10
Slave VM - 192.168.56.11
Wrote the bash script to be completely automated without ANY interactions (I stress 'ANY interactions', which means, once started, the bash script will run uninterrupted till completion). See bash script.
To make the bash script more reusable, I created a config file that stores the database variables needed to run the bash script. See config file.
The bash script sources/calls the variables from the config file into itself and temporarily stores them for use.
Created Ansible playbook to execute bash script on Slave node, ran it, and it ran successfully. See the images below for proof.
UPDATE: I discovered, when I tried cloning my project repo from GitHub and executing my Ansible playbook, that my bash script wouldn't run. I found that the problem was Windows line endings [or carriage returns (CR)] not working on Unix-like systems. So, I updated the Master VM provisioning and Ansible playbook to solve this problem and eliminate the bug. Now, if you clone my repo into your local machine and run my code it would work 'on your machine'. See new Ansible playbook execution result below.
Ansible playbook ran successfully
Verified that PHP Laravel application is accessible through Slave VM's IP address: 192.168.56.11
LAMP stack proof: Slave VM - 192.168.56.11
Created a cron job with Ansible playbook to check server’s (Slave VM) uptime every 12 am. Then ran crontab -l
in shell to check cron job list. See image below.
Cron job to check server's uptime every 12 am