All about Ansible modules
Tags: ansible
Published: 2021-10-28 13:38:49

*Hey here! If you prefer a video over text, we've got you covered!*
{% youtube 0yvsc7lSaVk %}

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjgcl7dlsvtukkbc35pc.png)

In this section we will be zooming in specifically on modules, which are essential for using Ansible to its fullest potential.

Ansible modules are used to simplify complex tasks. Ansible includes a standard module library with your installation. You are also able to write your own modules if needed. 

Modules are used inside playbooks (which we will cover in the next post) or can be used in the command line. 

Modules are often written using Python and can have the same functionality as any other Python script.

## Using a module from the command line
We have used a module before in the previous post. We used the ``win_ping`` module to test if there is a connection.
```bash
$ ansible Windows -m win_ping
```
As you can see the ``-m`` signals that the next name is the name of a module. 

Sometimes you want to use a module for a single action, without having to set up a playbook. In this case you may use the command line. Lets say you want to add Google Chrome on 250 Window machines. 

The command would look something like this:

```bash
$ ansible Windows -m win_chocolatey -a "name=googlechrome state=present"
```
In the above example, we are using the ``win_chocolatey`` module to install Google Chrome. The components of the above command are as follows:

- ``Windows`` -  Name of your host group
- ``win_chocolatey`` - Name of the module. In this case the windows Chocolatey module 
- ``-a "..."`` - Arguments for the module. The ``present`` argument specifies that if the software is not available then to make it available.  

Each module has its own arguments. You can use the documentation to look up what they are. 

## Available modules
Ansible provides the standard module library which consist of the following module category:

- [Cloud](https://docs.ansible.com/ansible/2.9/modules/list_of_cloud_modules.html): tools for managing specific cloud provider actions
- [Clustering](https://docs.ansible.com/ansible/2.9/modules/list_of_clustering_modules.html): contains functionality for managing clusters (such as Kubernetes)
- [Commands](https://docs.ansible.com/ansible/2.9/modules/list_of_commands_modules.html): general command and script execution tool set for nodes
- [Cryptography](https://docs.ansible.com/ansible/2.9/modules/list_of_crypto_modules.html): used for general encryption purposes
- [Database](https://docs.ansible.com/ansible/2.9/modules/list_of_database_modules.html): contains modules for managing database servers and database manipulation
- [Files](https://docs.ansible.com/ansible/2.9/modules/list_of_files_modules.html): used for reading, writing and altering files
- [Identity](https://docs.ansible.com/ansible/2.9/modules/list_of_identity_modules.html): used for managing user identity services
- [Inventory](https://docs.ansible.com/ansible/2.9/modules/list_of_inventory_modules.html): module for adding hosts to the Ansible playbook and groups
- [Messaging](https://docs.ansible.com/ansible/2.9/modules/list_of_messaging_modules.html): used specifically for Rabbitmq messaging
- [Monitoring](https://docs.ansible.com/ansible/2.9/modules/list_of_monitoring_modules.html): general purpose monitoring for (remote) nodes
- [Net Tools](https://docs.ansible.com/ansible/2.9/modules/list_of_net_tools_modules.html): DNS/IP management and tools for uploading/retrieving files from nodes
- [Network](https://docs.ansible.com/ansible/2.9/modules/list_of_network_modules.html): a vast tool set for all-purpose network management
- [Notification](https://docs.ansible.com/ansible/2.9/modules/list_of_notification_modules.html): used for sending push notification to messaging platforms
- [Packaging](https://docs.ansible.com/ansible/2.9/modules/list_of_packaging_modules.html): modules for the usage of most commonly known package managers 
- [Remote Management Modules](https://docs.ansible.com/ansible/2.9/modules/list_of_remote_management_modules.html): used for managing remote hardware resource pools
- [Source Control Modules](https://docs.ansible.com/ansible/2.9/modules/list_of_source_control_modules.html): used for managing source control providers such as Github, Gitlab and Bitbucket
- [Storage Modules](https://docs.ansible.com/ansible/2.9/modules/list_of_storage_modules.html): general storage group management
- [System Modules](https://docs.ansible.com/ansible/2.9/modules/list_of_system_modules.html): management tools for system specific configuration
- [Utilities modules](https://docs.ansible.com/ansible/2.9/modules/list_of_utilities_modules.html): contains utilities specific for Ansible usage
- [Web Infrastructure Modules](https://docs.ansible.com/ansible/2.9/modules/list_of_web_infrastructure_modules.html): used for managing web service related tools
- [Windows](https://docs.ansible.com/ansible/2.9/modules/list_of_windows_modules.html): contains a large tool set of utilities, used specifically for managing Windows hosts

You can find more information about these categories on [the Ansible website](https://docs.ansible.com/ansible/2.9/modules/modules_by_category.html).

## Writing custom modules
If you can't find a module that has your desired functionality, you can write your own. If you choose to write your own module, you can use any desired language. For learning more about making your own modules, you can find more at: [Developing Ansible modules — Ansible Documentation](https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html). 

## In short
In this post we have shown how you can execute modules from the command line and we have shown what module categories are available. 

In the next post we will show you how you can combine multiple modules together in playbooks. making it much easier to do large changes in one operation.

See you there!