Understanding Infrastructure as Code and Configuration Management (Ansible)

Understanding Infrastructure as Code and Configuration Management (Ansible)

·

5 min read

What's the difference?

When it comes to the cloud, Infrastructure as Code (IaC) and Configuration Management (CM) are inseparable. With IaC, a descriptive model is used for infrastructure management. To name a few examples of infrastructure: networks, virtual computers, and load balancers. Using an IaC model always results in the same setting.

Throughout the lifecycle of a product, Configuration Management (CM) ensures that the performance, functional and physical inputs, requirements, design, and operations of that product remain consistent.

Task-01

1.Read more about IaC and Config. Management Tools

Infrastructure as Code (IaC) orchestrates infrastructure through a descriptive framework, encompassing elements such as networks, virtual machines, and load balancers. When applied, an IaC model consistently generates an identical environment.

In contrast, Configuration Management (CM) upholds the uniformity of an application's behavior, encompassing its performance, functional and physical inputs, requirements, overall design, and operations throughout the entire life cycle of the product.

2.Give differences on both with suitable examples

The primary distinction between Infrastructure as Code (IaC) and Configuration Management (CM) lies in their respective focuses. IaC is centered on the management and provisioning of infrastructure through code, emphasizing the automation of infrastructure components such as virtual machines, networks, and storage in a repeatable and scalable manner.

In contrast, Configuration Management (CM) is dedicated to automating the configuration and management of software applications, operating systems, and servers. CM tools play a crucial role in automating tasks like software package installation, enforcing security policies, and managing system settings.

While IaC primarily addresses the infrastructure layer, dealing with the definition and automation of infrastructure components, CM operates at the application layer, automating configurations and management tasks related to software and servers. Despite their distinct focuses, both IaC and CM collaborate harmoniously, enabling teams to efficiently automate and manage their IT infrastructure.

3.What are most common IaC and Config management Tools?

Several tools facilitate the implementation of Infrastructure as Code (IaC) and Configuration Management (CM), each offering unique features and capabilities. Some widely used tools for IaC include:

  • Terraform: A tool designed for constructing, modifying, and versioning infrastructure in a secure and efficient manner.

  • CloudFormation: An AWS service enabling the definition of infrastructure as code specifically for AWS environments.

  • Pulumi: A versatile tool allowing the creation, deployment, and management of infrastructure across various clouds, using familiar programming languages.

Similarly, various tools are available for Configuration Management:

  • Chef: A configuration management tool streamlining the automation of software deployment, configuration, and management.

  • Puppet: A configuration management tool facilitating the automation of infrastructure, application, and compliance management.

  • SaltStack: A tool automating the configuration and management of software applications, operating systems, and servers.

  • Ansible: A widely adopted configuration management tool with dual capabilities for infrastructure automation. It employs a declarative language for defining infrastructure and applies to both on-premise and cloud environments.

IaC and CM complement each other, contributing to efficient IT infrastructure automation and management. IaC primarily addresses the infrastructure layer, while CM focuses on the application layer. Notable IaC tools include Terraform, CloudFormation, Ansible, and Pulumi, while common CM tools comprise Chef, Puppet, SaltStack, and Ansible.


What's this Ansible?

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.

Task-01

Installation of Ansible on AWS EC2 (Master Node)

sudo apt-add-repository ppa:ansible/ansible

sudo apt update

sudo apt install ansible

Launch an EC2 instance.

Establish an SSH connection to your EC2 instance.

Incorporate the Ansible PPA repository into your system via the provided command:

sudo apt-add-repository ppa:ansible/ansible

Execute the subsequent commands to update the package:

sudo apt update

Install Ansible on your system using the specified command:

sudo apt install ansible

After the installation concludes, ascertain the version of Ansible with the following command:

ansible --version

Task-02

Read more about Hosts file sudo nano /etc/ansible/hosts and ansible-inventory --list -y

The Ansible hosts file serves as a configuration file containing a roster of hosts or servers under Ansible management. Located at /etc/ansible/hosts on the Ansible control node, this file defines the inventory of manageable hosts. To modify the hosts file, any text editor can be employed. For instance, you can use:

sudo nano /etc/ansible/hosts

Once the file is accessible, insert the IP addresses or hostnames of the intended servers. The format for host entries is structured as follows:

[group_name]
host1
host2
host3

In this illustration, group_name acts as a user-defined identifier for the group of hosts, and host1, host2, and host3 represent the respective IP addresses or hostnames. The hosts file supports the definition of multiple host groups, each with its own set of hosts.

Post the addition of hosts, you can validate Ansible's inventory of manageable hosts by utilizing the ansible-inventory command with the --list and -y options:

ansible-inventory --list -y

This command presents a YAML-formatted list encompassing hosts and their attributes. These attributes include hostnames, IP addresses, and any other defined variables or group memberships for comprehensive insight into the managed infrastructure.

Task-03

  • Setup 2 more EC2 instances with same Private keys as the previous instance (Node)

  • Copy the private key to master server where Ansible is setup

  • Try a ping command using ansible to the Nodes.

Create 2 more instances with the same pem file that we used for creating master server earlier. In my case ansible_kp.pem

Now doing scp let's copy the pem file to our EC2 machine.

The file has been copied. After copying, give the file permissions using sudo chmod 600 ansible_kp.pem

Now go and edit the hosts file. Ansible hosts file is a configuration file that contains a list of hosts or servers.

Once the file is open, you can add the IP addresses of the servers also add private key file location to use for authentication.

After you have added the hosts to the file, you can verify the inventory of hosts that Ansible can manage using the ansible-inventory command.

ansible-inventory --list -y

Perform a connectivity test with Ansible by executing a ping command towards the nodes. To verify Ansible's ability to establish connections to your nodes, utilize the following command:

ansible all -m ping

The ping module will assess the validity of your credentials for accessing the nodes listed in your inventory file. A "pong" response signifies that Ansible is prepared to execute commands on that specific node. Alternatively, you can substitute "all" with "servers," which represents a group name.


Thankyou for reading until here. Happy Learning and Congifuring.