DMCA.com Protection Status Trending Topics About Devops: Mini-Project: Simple Automation Using Ansible

Tuesday, 7 September 2021

Mini-Project: Simple Automation Using Ansible

 In this Mini-Project, I implemented configuration management technology using an Ansible and running a simple service, Apache. And I’ll install it on 2 slaves at once. So, what are they?

Configuration Management

Configuration management systems are designed to make controlling large numbers of servers easy for administrators and operations teams. They allow controlling many different systems in an automated way from one central location.

Ansible

Ansible is an open-source software provisioning, configuration management, and application-deployment tool. It includes its own declarative language to describe system configuration.

Ansible is the simplest solution for configuration management available. It’s designed to be minimal in nature, consistent, secure and highly reliable, with an extremely low learning curve for administrators, developers, and IT managers.

How Does Ansible Work?

Ansible works by configuring client machines from a computer that has the Ansible components installed and configured.

It communicates over normal SSH channels to retrieve information from remote machines, issue commands, and copy files. Because of this, an Ansible system does not require any additional software to be installed on the client computers.

This is one way that Ansible simplifies the administration of servers. Any server that has an SSH port exposed can be brought under Ansible’s configuration umbrella, regardless of what stage it is at in its life cycle. This means that any computer that you can administer through SSH, you can also administer through Ansible.

Configuration files are mainly written in the YAML data serialization format due to its expressive nature and its similarity to popular markup languages. Ansible can interact with hosts either through command-line tools or its configuration scripts, which are known as Playbooks.

Apache

Apache web server is a popular open-source HTTP web server tool that is widely used for the deployment of webpages. It can be installed in any operating system.

Step 1 — Installing Ansible

To begin using Ansible as a means of managing your various servers, you need to install the Ansible software on at least one machine as a master.

To get the latest version of Ansible for Ubuntu, you can add the project’s PPA (personal package archive) to your system. Before doing this, you should first ensure that you have the package installed.

Step 2 — Configuring Ansible Hosts

As mentioned previously, Ansible primarily communicates with client computers through SSH. While it certainly has the ability to handle password-based SSH authentication, using SSH keys can help to keep things simple. But, the slaves here using EC2 Instances, so we use a keypair that has applied on to connect over SSH.

Because Ansible uses a python interpreter to run its modules, we need to install Python 2 on the host in order for Ansible to communicate with it. Repeat this process for each server you intend to control with your Ansible server.

Ansible keeps track of all of the servers that it knows about through a hosts file. We need to set up this file first before we can begin to communicate with our other computers.

And then add the following line above. It means that we have 2 groups named master that is installed Ansible and slave that have no services. There are vars that mean ubuntu as a user which will be connected by the master because the direct connection as a root user is not allowed. And don't forget the access key, I used the same key on all machine to make it easier.

Now that we have our hosts set up and enough configuration details to allow us to successfully connect to our hosts, we can try out our very first command.

And done! the slaves have been connected with the master now.

Step 3 — Make an Automation

This directory is used to store some files for starting new automation. And make sure we already on that directory after it.

Fill in web content as needed and then name the file with index.html. But I’ll fill it with:

Playbooks are YAML files containing a series of directives to automate the provisioning of a server.

YAML relies on indentation to serialize data structures. For that reason, when writing playbooks and especially when copying examples, you need to be extra careful to maintain the correct indentation.

The name for the playbooks file does not need to be considered, the most important is the format of the playbooks file, which is .yaml or .yml.

And here I’ll create simple playbooks for our 2 slaves that containing the command for changing user to root because we gonna install a package which is Apache2, copying the web page that we have been made to the directory of web server, and then restarting the Apache2.

It took a few minutes to run those tasks on the slaves.

Step 3 — See the Result

No comments: