Category: Amazon Elastic Compute Cloud

Ansible – Installation on Amazon EC2 Instance

You may use the following commands to install and verify the installation of Ansible on an Amazon EC2 instance. In this example, the AMI is Amazon Linux 2 AMI (HVM) (ami-0c02fb55956c7d316) and is provisioned in the Northern Virginia (US-EAST-1) region.

[root@ip-10-0-1-11 ~]# sudo amazon-linux-extras install ansible2 -y
[root@ip-10-0-1-11 ~]# ansible –version
ansible 2.9.23
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.18 (default, Jun 10 2021, 00:11:02) [GCC 7.3.1 20180712 (Red Hat 7.3.1-13)]


Terraform – Specify EC2 Instance Security Group

Using Terraform, you may specify the security group that will be associated with the Elastic Network Interface (ENI) of an Amazon EC2 instance during provisioning using the vpc_security_group_ids argument and the security group ID.

The syntax for the vpc_security_group_ids argument is displayed below.

vpc_security_group_ids = [aws_security_group.security-group.id]


Terraform – EC2 Security Group ICMP Rule

Using Terraform, you may configure a security group for an Amazon EC2 instance. The rule below will create an ingress rule that will allow all ICMP IPv4 traffic from any network.

As this is an example for education purposes, you may consider restricting the source IP address(es) in the cidr_blocks argument.

ingress {
description = “Allow all incoming ICMP – IPv4 traffic”
from_port = -1
to_port = -1
protocol = “icmp”
cidr_blocks = [“0.0.0.0/0”]
}


Amazon Web Services – Bootstrapping – Apache Installation

You may use the following commands to configure an Amazon EC2 instance to install and start the Apache web server upon boot. The commands should be placed in the Advanced Details dialog box during during the provisioning process of an EC2 instance.

#!/bin/bash
sudo su –
yum install -y httpd
systemctl start httpd