ARTH — Task 12 👨‍💻

Task Description 📃

Saranya. S
4 min readApr 2, 2021

12.1 Use Ansible playbook to Configure Reverse Proxy i.e. Haproxy and update it’s configuration file automatically on each time new Managed node (Configured With Apache Webserver) join the inventory.

12.2 Configure the same setup as 12.1 over AWS using instance over there.

TASK BEGINS……

|| NOTE: Create an AWS account

https://portal.aws.amazon.com/billing/signup#/start

STEP:1: To download the dynamic inventory requirements…

STEP:1.1:Download ec2.ini and ec2.py files

To download ec2.ini file:wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.iniTo download ec2.py file:wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py

STEP:1.2: Install packages

pip3 install boto
pip3 install boto3
pip3 install ec2

STEP:1.3:To make it executable

chmod +x ec2.py
chmod +x ec2.ini

STEP:2:Access key and Secret key….

STEP:2.1:Get IAM user access key and secret key

1.Go to Security, Identity, & Compliance → IAM
2.IAM Resources -> users -> Add User
3.set permissions -> Attach existing policies directly -> PowerUserAccess -> Create user

STEP:2.2:Create a file with the extension (.yml) and save these two key

cmd: <filename>.yml
key.yml

STEP:2.3:Update ec2.ini and ec2.py files

1.create a inventory path(for easy access) : mkdir /inventory
2.cd /inventory
3.move the files (ec2.ini,ec2.py) into this dir.
cmd: mv ec2.ini /inventory
mv ec2.py /inventory

||STEP:2.3.1:Open ec2.ini file

cmd: vim ec2.ini

Now, update the access key and secret key in “[credentials]” part

||STEP:2.3.2:Open ec2.py file

cmd: vim ec2.py

STEP:2.4:Now export both the key

export AWS_ACCESS_KEY_ID=’XXXXXXXXXXXXXXXXXXX’ 
export AWS_SECRET_ACCESS_KEY=’XXXXXXXXXXXXXXXXXXXXXX’

Now, change access permission

cmd: chmod 400 <filename>.yml

STEP:3:Set your ansible configuration file…

Note:

  1. Create the private key file using puttygen.
  2. Copy the private key file to the os in which your gonna run the ansible-playbook.[using winSCP]

STEP:4:Install haproxy and update config file…

||Install haproxy

cmd: yum install haproxy

||update configuration file

cmd: vim /etc/haproxy/haproxy.cfg

STEP:5:Write the ansible-playbook…

STEP:5.1: to launch web server and load balancers over AWS…

||vim ec2.yml

STEP:5.2: to do necessary work within launched webserver and load balancer

||vim haproxy.yml

STEP:5.3: to provide necessary instances details

||vim variable.yml

STEP:6: Run the ansible-playbook…

STEP:6.1: Run ec2.yml :: to launch ec2 instances

Note ::

To check:
*ansible all --list-hosts
*ansible all -m ping

STEP:6.2: Run haproxy.yml

STEP:7: Final step -to check the website….

cmd: <loadbalancer_ip>:8080

TASK ENDS….

--

--

No responses yet