Learn Ansible
上QQ阅读APP看书,第一时间看更新

Preinstallation tasks

As mentioned in the previous chapter, a LEMP stack is composed of the following elements:

  • Linux: In our case, this will be CentOS 7 again
  • NGINX: If you remember, it is pronounced as engine-x, and replaces Apache in our stack
  • MariaDB: As we have seen, this will be the database component
  • PHP: We will be using PHP 7.2 again for this

Before we install WordPress, we need to install and configure these components. Also, as this playbook is eventually going to be executed against publicly available cloud servers, we need to think about some best practices around our NGINX configuration.

Let's start by getting the initial structure of the playbook set up:

$ mkdir lemp lemp/group_vars
$ touch lemp/group_vars/common.yml lemp/production lemp/site.yml lemp/Vagrantfile lemp/.gitignore
$ cd lemp

Now that we have the basic layout, we need to put some content in the Vagrantfile and .gitignore files. Vagrantfile contains the following, similar to the previous chapters:

# -*- mode: ruby -*-
# vi: set ft=ruby :

API_VERSION = "2"
BOX_NAME = "centos/7"
BOX_IP = "192.168.50.5"
DOMAIN = "nip.io"
PRIVATE_KEY = "~/.ssh/id_rsa"
PUBLIC_KEY = '~/.ssh/id_rsa.pub'

Vagrant.configure(API_VERSION) do |config|
config.vm.box = BOX_NAME
config.vm.network "private_network", ip: BOX_IP
config.vm.host_name = BOX_IP + '.' + DOMAIN
config.ssh.insert_key = false
config.ssh.private_key_path = [PRIVATE_KEY,
"~/.vagrant.d/insecure_private_key"]
config.vm.provision "file", source: PUBLIC_KEY, destination:
"~/.ssh/authorized_keys"

config.vm.provider "virtualbox" do |v|
v.memory = "2024"
v.cpus = "2"
end

config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = "2024"
v.vmx["numvcpus"] = "2"
end

end

As you may have spotted, we are using a different IP address for this Vagrant box; the .gitignore file should contain a single line:

.vagrant

Now that we have the basics configured, we can make a start by writing the playbook to deploy and configure our initial software stack.