In this project we’ll focus on getting a simple test website set up in NGINX through ansible playbook on an Ubuntu 20.04 LTS server.
- Used Ansible Master server as Amazon Linux 2 and Client server as Ubuntu 20.04 LTS.
- Ansible Master server is installed with Ansible2.
- Variables such as Domain Name, Port No, Documentroot, User and Group are provided through the nginx.vars file.
- Amazon Linux 2 (Ansible-Master)
- Ubuntu 20.04 (Ansible-Client)
- Nginx (webserver)
- Ansible2
First let's create a directory in our master server. Now clone my Github repository ansible_nginx to your master server which is pre-installed with Ansible2. After cloning the repository, edit your Inventory file accordingly and modify the "nginx.vars" with the desired values.
yum install git -y
amazon-linux-extras ansible2 -y
git clone https://github.com/tajroshith/ansible_nginx.git
cd ansible_nginx
Now let's check the connection status to the client server via:
ansible -i inventoryfile all -f 1 -m ping
After successfully establishing connection to the remote server let's check for any error's in our playbook via:
ansible-playbook -i inventoryfile nginx.yml --syntax-check
Now let's execute the ansible-playbook via:
ansible-playbook -i inventoryfile nginx.yml
Here i encrypt the contents of "nginx.vars" via ansible-vault inorder to prevent the variables to be passed as plain text. Ansible-vault encrypts variables and files so you can protect sensitive content such as passwords or keys.
To encrypt a file, we use the ansible-vault command
ansible-vault encrypt nginx.yml nginx.vars inventoryfile EXAMPLE_KEY.pem
To prompt for the password:
ansible-playbook -i inventoryfile nginx.yml --ask-vault-pass