?? Ansible Task-2??

?? Ansible Task-2??

Deploying Web Server on AWS through ANSIBLE!

TASK DESCRIPTION:

?? Provision EC2 instance through ansible.

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

?? Configure the web server through ansible!

?? Create role for webserver to customize the Instance and deploy the webpage to root directory.

Let’s start with basic concepts.

What is Ansible??

Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code.It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management (allowing remote PowerShell execution) to do its tasks.

What is Amazon Web Services??

Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet.

What is Role??

Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files, templates, and modules. In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies writing complex playbooks, and it makes them easier to reuse.

So Let’s start to our task !!!

Step 1: Install Amazon Web Service (AWS) Software Development Kit (SDK)

Boto is AWS SDK. For connecting AWS we need to install boto library in our local environment.

pip3 install boto

Step 2: Launch AWS Instance

We have to write yml code for launch AWS instance.

->aws.yml

- name : Launch AWS Instance
  hosts : localhost
  vars_files  :
        - secure.yml
  tasks :
          - name : Launch EC2 Instance
            ec2 :
                    key_name : task2
                    instance_type : t2.micro
                    image : ami-0ebc1ac48dfd14136
                    wait : "yes"
                    count : 1
                    vpc_subnet_id : subnet-c9f6cca1
                    group_id : sg-0045c82f1f125e7e4
                    assign_public_ip : yes
                    region : ap-south-1
                    state : present
                    aws_access_key : "{{ username }}"
                    aws_secret_key : "{{ password }}"
            register: x
          - debug:
                    var: x.instances[0].public_ip

Now we have to create one more playbook called secure.yml to store aws_access_key and aws_secret_key.As we know this keys can’t be leave as public so we encypt this playbook with vault encyption.

->secure.yml

No alt text provided for this image

Now we launch instance by running aws.yml playbook.Let’s see what happen..

No alt text provided for this image
No alt text provided for this image

AWS Instance Launched Successfully !!!

Step 3: Fetching IP of instance dynamically we want to download ec2.py and ec2.ini scripts from github.

wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py


wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini

This scripts help to fetch IP dynamically.

Now to execute this files for retrive IP we should change their permission

chmod +x ec2.py

chmod +x ec2.ini

For execution we need to export some variables.

export AWS_REGION='ap-south-1'
export AWS_ACCESS_KEY_ID='aws_access_key'
export AWS_SECRET_ACCESS_KEY='aws_secret_key'

This variables export to our system to AWS and retrive IP.

Now we can check our IP

./ec2.py

No alt text provided for this image

Now check that our ip is properly pinging or not.

No alt text provided for this image

Step 4: Create role for webserver and deploy it

First we create one role

ansible-galaxy init role_name

No alt text provided for this image

Now we have to configure ansible.cfg to find path of role.

No alt text provided for this image

Now in task folder we write our code in main.yml file.

No alt text provided for this image

Lets create ansible playbook to run instance role and run playbook.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Now our Ansible playbook runs successfully.

Now we connect our AWS instance and check whether our webserver is running or not.Its running…..

No alt text provided for this image

Finally it's Done....

Thanks for reading..................

要查看或添加评论,请登录

Tushar Dighe的更多文章

  • Enhancing Cloud Security with Wiz: A Game-Changer for DevOps and Security Teams

    Enhancing Cloud Security with Wiz: A Game-Changer for DevOps and Security Teams

    Enhancing Cloud Security with Wiz: A Game-Changer for DevOps and Security Teams In today's fast-paced cloud…

  • AWS : NASA Case Study

    AWS : NASA Case Study

    Established in 1958, the National Aeronautics and Space Administration (NASA) has been working around the world—and off…

  • The World of “Big Data”

    The World of “Big Data”

    What is data? The quantities, characters, or symbols on which operations are performed by a computer, which may be…

  • ?? Hybrid Multi Cloud Task-3??

    ?? Hybrid Multi Cloud Task-3??

    INTEGRATION OF WORDPRESS RUNNING ON TOP OF KUBERNETES CLUSTER WITH AWS RDS.?? So, you might be thinking that what is…

    2 条评论
  • ?? Hybrid Multi Cloud Task-2??

    ?? Hybrid Multi Cloud Task-2??

    Using EFS service with Terraform. Objective: Perform the task-1 using EFS instead of EBS service on the AWS as…

  • ?? Hybrid Multi Cloud Task-1??

    ?? Hybrid Multi Cloud Task-1??

    To launch Webserver with AWS using Terraform code Steps required to launch the App using terraform:- 1. Create the key…

  • ?? DevOps Task-6 ??

    ?? DevOps Task-6 ??

    Integration of Jenkins with Kubernetes using groovy What is Groovy? Groovy is a Java-syntax-compatible object-oriented…

  • ?? DevOps Task-5 ??

    ?? DevOps Task-5 ??

    Deploy prometheus and grafana on the top of kubernetes . Tasks : Integrate Prometheus and Grafana and perform in…

  • ?? DevOps Task-4 ??

    ?? DevOps Task-4 ??

    In this article i have created a fully automated CI/CD build pipeline by using the technology git, github, Jenkins…

  • ?? Ansible Task-1 ??

    ?? Ansible Task-1 ??

    Integrate Ansible with Docker What is Ansible ?? Ansible is an open-source automation tool, or platform, used for IT…

    2 条评论

社区洞察

其他会员也浏览了