Setting up Ansible and Terraform in 2024

Jagan mohan Gade
2 min readJun 28, 2024

--

Easy way to set things up and running for Azure or AWS Cloud automation.

If you know what these tools are, jump in directly to setup ;)

What is Ansible?

Ansible is an open-source automation tool used for configuration management, application deployment, and task automation. It uses simple, human-readable YAML syntax to describe automation tasks, allowing for easier management of IT environments. Ansible operates agentlessly, relying on SSH for communication, which simplifies setup and maintenance.

What is Terraform?

Terraform is an open-source infrastructure as code tool that allows you to define and provision data center infrastructure using a declarative configuration language. It enables the automation of infrastructure setup, management, and scaling across various cloud providers. Terraform maintains a state file to track resource changes, ensuring consistent and repeatable infrastructure deployments.

If you have Azure or AWS Subscription ↓↓

Setting up in the Cloud (Azure or AWS) :

Create AWS EC2 or Azure VM by choosing Ubuntu Image.

SSH to the Virtual Machine / EC2 you created.(ssh username@public_ip)

In the home directory create a file named setup.sh and paste the below shell script.

#!/bin/bash
# Update package lists and install prerequisites
sudo apt-get update -y
sudo apt-get install -y software-properties-common
# Install Git
sudo apt-get install -y git
# Install Ansible
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt-get install -y ansible
# Install Terraform
# Add the HashiCorp GPG key
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
# Add the HashiCorp Linux repository
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
# Update and install Terraform
sudo apt-get update -y
sudo apt-get install -y terraform
# Verify installations
git --version
ansible --version
terraform --version
echo "Git, Ansible, and Terraform have been installed successfully."

Let us make the script file executable, run the below commands.

chmod +x setup.sh 
./setup.sh

Desired Output:

Hurray! you successfully installed Git, Ansible and Terraform

--

--