Task 12.2 |Dynamic Inventory in Ansible | Arth |

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!!

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Raspberry Pi and Software-Defined Radio Shows Which Plane Woke Your Cat

How ASTs power the GraphQL schema handling

How to SSH into a Docker container remotely as root or a non-root user

Android UI: Vertical Text View

GitHub And Git Commands

Writing MySQL proxy in GO for learning purposes: Part 2 — decoding connection phase server response

FlashVPS — Easy Servers Management Cloud Panel

FlashVPS — Easy Servers Management Cloud Panel

A Red Teamer’s Guide to GPOs and OUs

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
Gaurav Sharma

Gaurav Sharma

student

More from Medium

How to Install Terraform on Ubuntu / Rocky Linux & Fedora

Install terraform in rockylinux 8 and fedora 35

Learning IaC: Part One — Terraform

Running Ansible from Gitlab CI

Gitlab SSH Config Host File, Allowing Multiple Account SSH Access