Day 55: Getting Started with Ansible/Understanding Configuration Management with Ansible

Day 55: Getting Started with Ansible/Understanding Configuration Management with 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.

Benefits of Ansible

  • Free: Ansible is an open-source tool.

  • Very simple to set up and use: No special coding skills are necessary to use Ansible’s playbooks (more on playbooks later).

  • Powerful: Ansible lets you model even highly complex IT workflows.

  • Flexible: You can orchestrate the entire application environment no matter where it’s deployed. You can also customize it based on your needs.

  • Agentless: You don’t need to install any other software or firewall ports on the client systems you want to automate. You also don’t have to set up a separate management structure.

  • Efficient: Because you don’t need to install any extra software, there’s more room for application resources on your server.

Ansible Architecture

Now let’s talk a bit about the pieces that make up the Ansible environment.

1. Modules

Modules are like small programs that Ansible pushes out from a control machine to all the nodes or remote hosts. The modules are executed using playbooks (see below), and they control things such as services, packages, and files. Ansible executes all the modules for installing updates or whatever the required task is, and then removes them when finished. Ansible provides more than 450 modules for everyday tasks.

2. Plugins

As you probably already know from many other tools and platforms, plugins are extra pieces of code that augment functionality. Ansible comes with a number of its plugins, but you can write your own as well. Action, cache, and callback plugins are three examples.

3. Inventories

All the machines you’re using with Ansible (the control machine plus nodes) are listed in a single simple file, along with their IP addresses, databases, servers, and so on. Once you register the inventory, you can assign variables to any of the hosts using a simple text file. You can also pull inventory from sources like EC2 (Amazon Elastic Compute Cloud).

4. Playbooks

Ansible playbooks are like instruction manuals for tasks. They are simple files written in YAML, which stands for YAML Ain’t Markup Language, a human-readable data serialization language. Playbooks are really at the heart of what makes Ansible so popular is because they describe the tasks to be done quickly and without the need for the user to know or remember any particular syntax. Not only can they declare configurations, but they can orchestrate the steps of any manually ordered task, and can execute tasks at the same time or at different times.

Each playbook is composed of one or multiple plays, and the goal of a play is to map a group of hosts to well-defined roles, represented by tasks.

5. APIs

Various APIs (application programming interfaces) are available so you can extend Ansible’s connection types (meaning more than just SSH for transport), callbacks, and more.

Now that we’ve come this far to understand what Ansible is, let us next look into the Ansible tower.

What is Ansible Tower?

Ansible Tower is Red Hat’s commercial web-based solution for managing Ansible. Its best-known feature is an easy-to-use UI (user interface) for managing configurations and deployments, which is a significant improvement over the original UI. Ansible Tower contains the essential features of Ansible, especially those that are easier to see in a graphical format rather than a text-based format. It is free for up to 10 nodes.

Task-01

  • Installation of Ansible on AWS EC2 (Master Node)

    Launce EC instance and setup Master node

To begin using Ansible as a means of managing your server infrastructure, you need to install the Ansible software on the machine that will serve as the Ansible control node.

From your Master(control) node, run the following command to include the official project’s PPA (personal package archive) in your system’s list of sources:

sudo apt-add-repository ppa:ansible/ansible

Update system packages

sudo apt update

Following this update, you can install the Ansible software with:

sudo apt install ansible

Task-02

  • read more about Hosts file sudo nano /etc/ansible/hosts ansible-inventory --list -y

The inventory file contains information about the hosts you’ll manage with Ansible. You can include anywhere from one to several hundred servers in your inventory file, and hosts can be organized into groups and subgroups. The inventory file is also often used to set variables that will be valid only for specific hosts or groups, in order to be used within playbooks and templates. Some variables can also affect the way a playbook is run, like the ansible_python_interpreter variable that we’ll see in a moment.

To edit the contents of your default Ansible inventory, open the /etc/ansible/hosts file using your text editor of choice, on your Ansible control node:

sudo nano /etc/ansible/hosts

Add Host servers IP under this file and key should be same for all the instances.

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.

Setup instances with Master node.

Copy the private key and provide the permissions i.e.Read/write/execute(chmod 777 filename)

From your local machine or Ansible control node, run:

ansible all -m ping -u ubuntu/root(depends upon user)

This command will use Ansible’s built-in ping module to run a connectivity test on all nodes from your default inventory, connecting as root. The ping module will test:

Happy Learning..!!

Thank you for reading!! Hope you find this helpful.

#day55#90aysofdevops#devopscommunity#

Always open for suggestions..!!

Thank you Shubham Londhe !