Setting Up Ansible for EC2 With Dynamic Inventory

Setting Up Ansible for EC2 With Dynamic Inventory

In this article, I will demonstrate how to provision EC2 instance using ANSIBLE and how do set up a more agile environment using the DYNAMIC INVENTORY. Provision OS on top of AWS cloud using Ansible and make the environment more agile using dynamic inventory.

In this article, I will demonstrate how to provision EC2 instance using ANSIBLE and how do set up a more agile environment using the DYNAMIC INVENTORY.

→Pre-requisites:

— >RedHat Ansible downloaded and configured in the local system.

Do check out my previous article for Ansible👇👇:

~Problem Statement:

♦️ Deploy Web Server on AWS through ANSIBLE!

🔹 Provision EC2 instance through ansible.

🔹 Retrieve the IP Address of instance using the dynamic inventory concept.

🔹 Configure the webserver through ansible!

  • As Ansible is built on top of python, a Python Software Development Kit (SDK) is required that enables the configuration of AWS services. The package is an object-oriented API named boto3.
pip3 install boto3   //assuming python3 is installed

→STEP-1)

  • In the first step, I provisioned an ec2 instance with this playbook.
  • Here, the RedHat system itself calls the API for configuration on AWS, and this procedure is done on the local machine that’s why the host is supposed to be localhost.
  • For authentication to the AWS account, create one IAM user that has less privileged than the root account. The AWS_ACCESS_KEY and AWS_SECRET key are passed explicitly through an Ansible vault named secret.yml

Image for post

Image for post

Encrypted Vault🔒

- hosts: localhost
  vars_files:
      - secret.yml
  tasks:
   - name: Provision os in AWS
     ec2:
      key_name: "keytask" //keypair to be attached to the instance  
      instance_type: "t2.micro"
      image: "ami-0ebc1ac48dfd14136"  //amazon linux 
      count: 1
      wait: yes
      vpc_subnet_id: "subnet-e7780dab"
      region: "ap-south-1" //asia-pecific-south region of AWS
      state: present
      assign_public_ip: yes
      group_id: "sg-0512d293cfb4af6e4" //security group 
      aws_access_key: "{{ myuser }}"
      aws_secret_key: "{{ mypass }}"
     register: ec2   
- debug:
       var: ec2.instances[0].public_ip

Image for post

aws ansible linux web-server dynamic-inventory

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Deploy Web Server on AWS through ANSIBLE

This article covers the Integration of Ansible with AWS. Here I have used AWS-EC2 instance as my base OS to launch my web page and this setup is created and managed by Ansible modules, playbooks and Roles.

Deploy Apache Web-Server In Docker Container In AWS EC2 Instances Using Ansible-Playbook.

Technologies which are going to be discussed in this blog: Ansible, Docker, Amazon Web Service(AWS). Docker provides the ability to package and run an application in a loosely isolated environment called a container.

Deploying Web Server & HAProxy Load Balancer on AWS Using Ansible

Provisioning AWS EC2 Instances and Security Group using Ansible Playbook and then Deploying HTTPD Web Server and HAProxy Load Balancer Server using Ansible Roles.

SQL Server Always On Availability Groups for SQL Server Linux instances

SQL Server Always On Availability Groups for SQL Server Linux instances. In this article, we will configure the availability groups between two Linux VM’s. We create an availability group between two Linux instances. For this purpose, we require two virtual machines in the Oracle VM VirtualBox.

whatsapp web-w app web-webs whatsapp »

whatsapp web-w app web-webs whatsapp-web.whatsapp.com-wsp web-web.whatsapp.com qr-whats up online-whatsappwebsite