In this guide, we’ll focus on getting a Wordpress 5.7.2 instance set up on a LEMP stack (Linux, Nginx, MySQL, and PHP7.2) on an Ubuntu 18.04 LTS server.
- Easy to provision a wordpress site based on Nginx in Ubuntu Server.
- Variables such as Domain name, Wordpress database name, DB user, DB password and MySQL root password is provided through the variable.vars file.
- In this scenario we have used Master server as Amazon Linux 2 and Client server as Ubuntu 18.04 LTS with desired ports 22, 80 opened.
- Master server installed with Ansible2 (For your reference visit How to install Ansible)
Inventory , File, Database, Command
First create a directory in master server .Then, clone this Github repository nginx_wordpress_ubuntu to your master server which is pre-installed with Ansible2. Once you cloned this repository, edit your "hosts" file (Inventory file) accordingly and modify the "variables.vars" with the desired values. Also here I have used SSH private KEY based login. So I have copied the ssh private key file as "KEY_NAME.pem" in the same directory with read permission granted to the User/Owner (eg: chmod 400 KEY_NAME.pem).
Check the connection status to your client server via:
ansible -i hosts ubuntu -m ping
Once you have established the connection, then check for any syntax error in the playbook
ansible-playbook -i hosts main.yml --syntax-check
If you are good to go, then execute the ansible-playbook:
ansible-playbook -i hosts main.yml
Here we have used the "variables.vars" file to pass the variables as a plain text, to overcome this we can encrypt the files with a password. Ansible_vault encrypts variables and files so you can protect sensitive content such as passwords or keys rather than leaving it visible as plaintext in playbooks or roles.
To encrypt a file, use the ansible-vault encrypt command.
ansible-vault encrypt main.yml hosts KEY_NAME.pem variables.vars
To prompt for the password:
ansible-playbook -i hosts --ask-vault-pass main.yml