Configuring Reverse Proxy on Cloud using Ansible
Configuration Management and the Cloud
For configuration management we use automation tools like puppet, chef, ansible, etc. Here we will configure HAProxy on AWS cloud using Ansible.
First we start by launching at least 3 instances, one the controller node and others, the managed nodes.
In the home directory of the controller node, put the key and create a workspace.
Use yellow-dog updater modified to install python3 and pip to install Ansible.
In the workspace create the Ansible config file ansible.cfg
[defaults]
inventory = inventory
gpg_key_checking = False[privilege_escalation]
become = True
become_user = root
become_method = sudo
become_ask_pass = False
Now create an inventory file.
[lb]
172.31.15.113 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/mykey.pem [backend]
172.31.42.180 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/mykey.pem
172.31.47.153 ansible_user=ec2-user ansible_ssh_private_key_file=/home/ec2-user/mykey.pem
When running as root, run the following command to add ansible location to PATH variable.
export PATH="/usr/local/bin:$PATH"
Create an Ansible Playbook in the workspace. Create two plays.
Run the playbook!
Now use public IP of the load balancer. You will see that HAProxy automatically does reverse proxy via round robin.
Here’s the code for local VirtualBox lab setup: Ansible HAProxy
Feel free to contact on my LinkedIn.