10 Ansible Modules We Need to Know

Ansible is one of the mostly used open sourced IT config. It is also automation & management tool. It is very popular tool. This platform generally employs the human readability. Also, it has YAML templets which are very easy to understand. This allows the users to run their program as continuous task. This is possible with the help of the Ansible modules. This will happen automatic without any help of any advanced program. 

Ansible tool is agent less. It means nodes or server doesn’t require any of the software. It will eliminate all the security issues. This makes IT CM Smoother as well as secured. 

This tools work to connect the nodes & transmit the small programs. These are called as the Ansible modules. Mostly it will execute remotely. This plays very important role in making the tool as the push architecture. From the Ansible different configs are pushed to the different servers. This is possible without the need of the agents. This differs from pull model. In simple words we can able to say that, this CM is agents-based system. Using this IT configs are pulled. 

Introduction to Ansible Models:

Generally, we use Standalone scripts inside ansible playbooks. Such scripts are known as Ansible modules. This playbook consists of play and this play consists of various task. Are you new to the playbook? Then it seems to be confused. But when you start to work and write in the playbook it is very easy for you.

Generally, the resources as well as their status which are present in the YAML files are mapped with the modules. It is very important to have knowledge about these ansible modules. These modules help the developers to manage each and everything virtually. They manage the following things. They are,

  • Security configuration.
  • Private cloud.
  • OpenStack.
  • Azure.
  • AWS.
  • Container orchestrators.
  • Containers themselves.
  • Load balance.
  • Firewalls.

For automating various tasks generally, we use some famous ansible modules. In this article we are going to discuss about the top 10 ansible modules.

Why we need to develop the Ansible modules?

In general, ansible has many modules. But still we need some changes which are not covered. In such cases we need to develop new modules with the required changes. The most important thing before developing the new module is, we need to check the galaxy website of the Ansible. This is to conform whether the required module is available or not. 

Following are some of the cases when we need to develop the new module

  • The traditional CM such as template, files, etc. doesn’t solve our issues.
  • Need for using more complex set of command / API which are call via curl for completing our task.
  • Playbook is non-deterministic as well as complex.

10 Ansible modules:

Generally, we have a greater number of the Ansible modules which we use in our project. Especially for the various functions. We have some most famous modules. These modules help us in many projects. These ansible modules are very easy for using. So, we must know about these modules. Now in the below section we will discuss about them in detail.

1st Module: Module of package management:

We have few modules for the package managers like APT as well as DNF. This helps us for installing various packages. The main functionality is highly depending on this package manager. Using these modules, we can able to do the following task in the package. They are,

  • Install.
  • Upgrade.
  • Downgrade.
  • Remove.

The name given for this module are also easy to understand. Following are some examples for these modules.

For installing the web server of the Apache as well as MariaDB SQL:


For installing as well as downloading the packages:


2nd Module: Module of Ansible Yum:

Using this module, we can able to install various services. Following is the syntax of this module. 

Using this in our system, we can able to install the Apache 2. The very important thing is we need to use the new version instead of using older version.

3rd Module: Module of Ansible Command:

For executing the commands in remote node, we use this module. Mostly this module is used by the developers as well as experts. They use this mainly for executing Linux command which are very simple. Especially on remote servers. We can also say this as the part of standalone / host group servers. Also, we can able to use this for performing the shell commands. 

If we use shell commands which are more complex? Or if we use many commands with the PIPE? In such cases these modules won’t work. For this we need to use the shell modules. Inside of PIPE if we choose the characters just like |><. Especially in our command. Then we should use shell modules.

This will be OK as well as perfect for command modules.

4th Module: Module of Ansible User:

In system which are based on the Linux for managing various users we use this module. Instead of using this we can use the following. They are,

  • Create.
  • Add groups.
  • Set password.
  • Delete user’s account.

Let’s see with an example. Creating the user using this module.

Here we are adding user as exampleuser. This is with the specific uid. Also, the primary group as the admin.

The one and only parameter is the name. This should be the name of the account user. If we don’t provide with the password? Then the account will display in the locked state. It means we are not able to be logged in using password option.

5th Module: Module of Ansible Lineinfile:

For performing the following task, we should use this module. They are,

  • Altering.
  • Removing the existing line.
  • Inserting a line.
  • Replacing the lines.

Now let’s see with an example. For inserting a new line, we need to set file path. For modifying with the help of path or dest. We can able to insert the lines via line parameter. This line will enter to EOF. If this line is already existing in system? Then it will not be added.

6th Module: Module of Ansible File:

In server scripts, the common task is creating various new files. In the Ansible tools, there are many methods to create the new files. Even we can able to set various group permission. Also, we can able to assign owner to these files. We can also able to create the files with the content. These will set the attributes of the directories, files as well as symlinks. For creating the new file generally, we need to assign two critical parameters. They are,

  • Path:

This refers with the exact location of the file where we are going to create the new file. Generally, there are 2 path types. They are,

  • Absolute path.
  • Relative path.

Also, we want to include file name of the file which we are going to create.

  • State:

During the new file creation, we want to set all the state parameters for touch. This functions as touch operations in the Linux. 

Now, we are going to see the creation of file with foo-conf as the name. Also, we need to set 0644 as the permission. This is possible with the help of this module.

7th Module: Module of Ansible Template:

Creating the static files in order to manage the server config is not at all a perfect solution. All we need is more effective way which gives more benefits. So, in such cases we are using this module. All the config parameters are there in the templates. While executing the playbook, variables get replaced with required values. We can able to perform more using the Jinj2 which is the template engine. 

For example:

8th Module: Module of Ansible Windows:

For the windows modules, all we need is to test this module. We want to enable as well as configure powershell. This is in order to manage windows machines. All we need is just the machine with Linux control. Following are some of the Ansible windows module. They are,

Setting permission for the system user / group:

Adding audit rule for the files, registry keys or folders:

Getting information about the Schedules Tasks of the windows:

9th Module: Module of Ansible Archive:

Compressed archives for difference files can be created with the help of this module. This module will assume that source file of the compression may exist on target. For example.

10th Module: Module of Ansible Cli_Command:

This module will be available only in the Ansible 2.7. It offers the method of platform-agnostic for the configuration which is based on the push text. The devices are connected with the help of network-cli command. For example:

Conclusion:

In the latest Ansible version we can able to find many Ansible modules. Also, with lot of commands. These 10 modules play a major role in Ansible. These are more powerful modules. With the help of these modules, we can able to automate various projects. Hope this article clearly explains about these ten modules. 

December 16, 2020
© 2023 Hope Tutors. All rights reserved.

Site Optimized by GigCodes.com

Request CALL BACK