First, we want to create a new project, so let's create a new folder called lemp-stack
and initialize a new ubuntu/trusty64
Vagrant project within it by executing the following commands:
mkdir lemp-stack cd lemp-stack vagrant init ubuntu/trusty64 ub
The easiest way for us to pull in the MySQL Puppet module is to simply add it as a git
submodule to our project. In order to add a git
submodule, our project needs to be a git
repository, so let's initialize it as a git
repository now to save time later:
git init
To make the virtual machine reflective of a real-world production server, instead of forwarding the web server port on the virtual machine to another port on our host machine, we will instead network the virtual machine. This means that we would be able to access the web server via port 80
(which is typical on a production web server) by connecting directly to the virtual machine.
In order to ensure a fixed IP address to which we can allocate a hostname on our network, we need to uncomment the following line from our Vagrantfile by removing the #
from the start of the line:
# config.vm.network "private_network", ip: "192.168.33.10"
The IP address can be changed depending on the needs of our project.
As this is a sample LEMP stack designed for web-based projects, let's configure our projects directory to a relevant web folder on the virtual machine:
config.vm.synced_folder ".", "/var/www/project", type: "nfs"
We will still need to configure our web server to point to this folder; however, it is more appropriate than the default mapping location of /vagrant
.
Before we run our Puppet provisioner to install our LEMP stack, we should instruct Vagrant to run the apt-get update
command on the virtual machine. Without this, it isn't always possible to install new packages. So, let's add the following line to our Vagrant file within the |config|
block:
config.vm.provision "shell", inline: "apt-get update"
As we will put our Puppet modules and manifests in a provision
folder, we need to configure Vagrant to use the correct folders for our Puppet manifests and modules as well as the default manifest file. Adding the following code to our Vagrantfile will do this for us:
config.vm.provision :puppet do |puppet| puppet.manifests_path = "provision/manifests" puppet.module_path = "provision/modules" puppet.manifest_file = "vagrant.pp" end