Task 12.2 |Dynamic Inventory in Ansible | Arth |
3 min readJul 13, 2021
Task Description
Task — 12.2: Configure the same setup as 12.1 over AWS
using instance over there.
Pre-Requisites
- To use AWS instance as Target node in ansible we need to do some setup.
Firstly we have to install aws.py
- Now we have to transfer the AWS pem key from local system to the ansible VM.
- Third, we need to install python3 for running the ec2.py.
# yum install python3-y
- Third, we need to install boto3 library which is python3 SDK for AWS.
Steps
- First, we have to configure ansible inventory for AWS.
Here we provide path where we put the aws.py file & pem key in inventory path.
We also include privilege escalation for root access.
- Now we make both aws.py file & AWS private pem key executable by using below commands:-
# chmod +x ec2.py
# chmod 400 <private_key>.pem
- Now, we need to install boto3 library which is python3 SDK for AWS.
pip install boto3
- The most important step of this task is to set environment variable for authentication
# export AWS_ACCESS_KEY_ID = <ACCESS-KEY>
# export AWS_SECRET_ACCESS_KEY = <SECRET-KEY>
# export AWS_REGION = <AWS-REGION>
Now everything is configured, let’s check that we have everything right or not.
Check
- First to check that ec2,py is running perfectly or not.
# ./ec2.py --list
Output —
- Now we can display the target ec2 nodes.
# ansible all — list-hosts
- To pass tag as hosts in inventory file we use this as example “tag_country_us”.
# Problem I faced in this task
- First of all i faced lots of problem while configuring the dynamic inventry.
- Every time when I start the VM i have to set all three environment variable again.
- Now a suggestion if on list host command, you get wrong credential error then “Power off the Machine” without saving it’s state.
Hope This Article was help for you & you are able to perform your task. Please share this with all your Medium friends.
Thanks For Reading!!