Ansible Modules

Ansible Modules

The modules are different blocks of code that are utilized from the command line or inside the playbook task.

In Ansible, these modules are additionally alluded to as task plugins or library plugins.

Ansible is imported with a few modules called module library that can be executed legitimately or distant hosts through the playbook.

Clients can likewise compose their modules. These modules can control administrations, framework assets, records, packages, and so on and handle running framework commands.

The following commands help in executing three unique modules on the command line.

 ansible webservers - m administration - a "name=httpd state=started"
 ansible webservers - m ping
 ansible webservers - m order - a "/sbin/reboot - t now" 

All modules underpin taking agreements. Primarily all modules take key=value contentions, space delimited.

Few modules don’t receive arguments, and the shell/order modules take the line of the command, which you need to run.

Ansible modules run fundamentally in a similar way as it would from the playbook. For example,

 - name: reboot the servers
 command:/sbin/reboot - t now 

We can apply a different approach to pass arguments for utilizing YAML syntax, and it is likewise known as complex args.

 - name: restart webserver
     service:
 name: httpd
 state: restarted 

In general, every module returns JSON format information. However, command-line or playbooks don’t return the same format. In case you're composing your module, it implies you don't need to compose modules in a specific language. You get the opportunity to pick.

Modules must be idempotent and abstain from rolling out any improvements on the off chance that they identify the present status coordinates the ideal last state. When utilizing Ansible playbooks, these modules can trigger "change functions" through advising "handlers" to execute extra assignments.

Documentation of all modules can be seen from the command-line with the Ansible-doc apparatus:

ansible-doc yum

For a list of all accessible module, see the Collection docs, or execute the accompanying at a command prompt:

ansible-doc – l

Module Maintenance and Support

While utilizing a module, you will find a bug. You might need to realize where to report that bug, who is liable for solving this problem, and how you can follow the module changes. On the off chance that you are a Red Hat supporter, you might need to know whether you can get uphold for the problem you are confronting.

Beginning in Ansible 2.10, most modules are present in collections. The dispersion strategy for all collections shows the maintenance and backing for the modules in that collection.

Maintenance

CollectionLocation of codeMaintained by
Ansible.builtinRepositories on GitHub like ansible/ansible repoFundamental team
Distributed on GalaxySeveral but go according to the repo link.Partners or community
Distributed on automation hubSeveral but go according to the repo link.Partners or content team

Issue Reporting

On the off chance that you discover a bug that influences a module in principle Ansible repo, otherwise called ansible-base:

  1. Affirm that you are running the most recent stable rendition of Ansible.
  2. Take a look at the problem tracker inside the Ansible repo to check whether a problem has previously been caught.
  3. Make an issue if one doesn’t exist so far. Add as much information as possible about the behavior you found.

Support 

Red Hat upholds all modules that stay in ansible-base and all collections facilitated in Automation Hub. Red Hat upholds no different modules or collections. If you possess membership in the Red Hat Ansible Automation Platform, you can discover a lot of data and assets on the Red Hat Customer Portal.

Return Values

Ansible modules ordinarily return an information structure that can be enrolled into a variable or seen legitimately when yield by the ansible program. Every module can alternatively report its remarkable return values.

backup_file

For those modules that actualize backup=no|yes when controlling documents, a way to the reinforcement record made.

"backup_file": "./foo.txt.32729.2020-10-15@06:24:19~"

changed

A Boolean demonstrating if the assignment needed to make changes.

"changed": true

failed

A boolean that demonstrates if the undertaking was crashed or not.

"failed": false

msg

A string with a conventional message handed-off to the client.

"msg": "line added"

rc

A few modules execute order line utilities or are intended for executing orders legitimately (crude, shell, order, etc.). This field contains the 'return code' of these utilities. 

"rc": 239

skipped

A boolean that demonstrates if the undertaking was skipped or not

"skipped": true

stderr

A few modules run command-line utilities or are designed for executing commands legitimately (crude, shell, command, etc.). This field contains the mistake yield of these utilities.

"stderr": "ls: foo: No such file or directory."

stderr_lines

From the moment it is returned, we likewise consistently give this field a rundown of strings or lines, a single thing for every line from the first.

 "stderr_lines": [
 "ls: doesntexist: No such file or directory."
 ] 

stdout

A few modules run the command line utilities or are designed for executing orders or commands legitimately (crude, shell, order, etc.). This field contains the typical yield of these utilities.

"stdout": "foo!"

stdout_lines

From the moment stdout is returned, Ansible consistently gives a rundown of strings. Each string contains one thing for every line from the first yield.

"stdout_lines": [
 "foo!"
 ]