Javatpoint Logo
Javatpoint Logo

Ansible EC2 Create Instance

What is EC2

EC2 is a web service that provides servers in the cloud which are customized as per need. It is highly scalable and works on a pay-as-you-go model.

EC2 is a web service that aims to simplify developers' lives by providing secure and resizable computing capacity in the cloud. With EC2, scaling up or down our infrastructure is very easy based on the demand. It can be integrated with almost all the services on amazon, and the best part is that we only pay for what we use.

Benefits of EC2

  1. Elastic web-scale computing
  2. Flexible
  3. Scalable
  4. Reliable
  5. Secure
  6. Inexpensive

What is AMI

AMI stands for Amazon Machine Images, and AMI provides the information required to launch the EC2 instance. It includes the pre-configured templates of the operating system that runs on AWS. Clients can send off various occurrences with a similar design from a solitary AMI.

Security groups in AWS

  1. A security bunch goes about as a virtual firewall that controls the traffic for at least one example.
  2. The traffic can be either inbound or outbound from an instance.
  3. It secures the instance through IP protocol, port access, and the source or destination address.
  4. Instances associated with the security group cannot talk to each other if there is no explicit rule to allow it.
  5. It can be attached to an Elastic Network Interface(ENI).

What is an Instance?

An example is a virtual server for running applications on Amazon's EC2. It can likewise be perceived as a little piece of a bigger PC, a minuscule part that has its own hard drive, network association, operating system, and so forth. Yet, it is all virtual.

Steps to use EC2

  1. The first thing is to create an AMI, which is Amazon Machine Images, the software, and the application packages we would need to run our application.
  2. The second is to choose the hardware; here, it is the instance type; depending on the workload and the intents of the workload, we will be choosing the size of the hardware.
  3. Finally, we would configure the instances and how many instances we want to know which subnet we want them in, what will be in the instance's stop or terminate behaviour, and if we want to update patches when the instance starts running. All this information goes here when we configure the instance.
  4. In step four, we add additional storage to the EC2 instance.
  5. Then in the fifth step, we add tags, use tags, or we would configure tags to identify an EC2 instance at a later point easily.
  6. In step six, we would configure the firewall, also called the security group for the EC2 instance. It is where we would allow or deny connection from the external world to this particular EC2 instance. It works inside and outside, and this firewall blocks the connection based on port number and IP address.
  7. In step seven, we review all the configurations we have done and make sure that the configuration is what we wanted, and at last, click on submit, and it will launch an EC2 instance.

For working on Ansible, we need first to set up a few things,

  1. AWS user account
  2. Ansible
  3. Python
  4. Boto

Just go to the Amazon AWS server to create the AWS account and follow the signup process. Once the AWS account is created, we must create the IAM user (As we will need a secret key and secret ID).

Open the AWS Console, search for IAM (Identity and Access Management) and follow the steps to create a user, and take note of the Access Key and Secret Key that Ansible will use to set up the instances.

Now if we go to the Amazon console, we will see the server has been launched successfully.

Once we finish the AWS account and the User creation, we can move forward and install the required things.

Ansible

Install Ansible on an RHEL/CentOS Linux-based system

  1. $ sudo yum install Ansible

Install Ansible on a Debian/Ubuntu Linux-based system

  1. $ sudo apt-get install software-properties-common
  2. $ sudo apt-add-repository ppa:Ansible/Ansible
  3. $ sudo apt-get update
  4. $ sudo apt-get install Ansible

Install Ansible using pip

  1. $ sudo pip install Ansible
  2. $ Once installed, we can verify by Ansible -version this command.

Python

  1. $ sudo apt-get update
  2. $ sudo apt-get install python3.6

Boto

Boto is a Python bundle that gives a point of interaction to AWS.

First, install the pip

  1. $ sudo apt install python3-pip or
  2. $ yum install python-pip

Now install boto

  1. $ pip install boto

Next Topic#Ansible Handlers





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA