Provisioning Load Balancer on AWS Instances using Ansible

Load balancing is defined as follow:

Since I have already all the concepts used in today’s task in the previous blog therefore I am directly moving on to the practical part today.

Copyright Ayush Gupta


pip3 install boto
ansible-vault encrypt <filename.yaml>
ansible-vault decrypt <filename.yaml>
ansible-vault view <filename.yaml>ansible-vault edit <filename.yaml>
ansible-galaxy init<rolename>
vars/main.yml     → Variable declaration
template/main.yml Dynamic Files
here main working of the role to be written
handlers/main.yml → tasks that you want to run or to be called when some condition meets → Is used in the role for instruction or as description file of the role for the user to make changes or how to use that role.
we have other folders to but right now knowing about them not required for completing this task
Ansible playbook for running above roles
Address of Conf file of Ansible
Underlines are very important for ansible to be used while using for AWS
->In the above file, we specified the inventory folder as /hosts [which contain all the info required for ansible to connect to a Managed Node]        ---->remote_user for telling ansible to go as a user ec2-user 
-> roles_path= used to specify the path for ansible to search for all the roles used inside the playbook in that particular folder
->private_key_file= is specified for ansible so that AWS should grant access to ansible for making changes inside the AWS cloud instance.
Command given below I run in /hosts folder which I passed to ansible as it's inventory folder now use the command to fetch the required file.
chmod +x
chmod +x ec2.ini
Commands need to be run inside the /root folder
export EC2_INI_PATH=path_of_ec2.ini_file
export AWS_ACCESS_KEY_ID="aws_access_key"
export AWS_SECRET_ACCESS_KEY="aws_secret_key"
export AWS_REGION='app-south-1'
chmod 400 <keyaddress/keyname.pem>
chmod +x /hosts/host
ansible-playbook --ask-vault-pass <playbook>
Showing that instances are successfully launched over the AWS cloud
Haproxy file saved over the LoadBalancer



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store