All about Ansible modules
Group3-kb84
Posted on October 28, 2021
Hey here! If you prefer a video over text, we've got you covered!
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.
$ 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:
$ 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. Thepresent
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: tools for managing specific cloud provider actions
- Clustering: contains functionality for managing clusters (such as Kubernetes)
- Commands: general command and script execution tool set for nodes
- Cryptography: used for general encryption purposes
- Database: contains modules for managing database servers and database manipulation
- Files: used for reading, writing and altering files
- Identity: used for managing user identity services
- Inventory: module for adding hosts to the Ansible playbook and groups
- Messaging: used specifically for Rabbitmq messaging
- Monitoring: general purpose monitoring for (remote) nodes
- Net Tools: DNS/IP management and tools for uploading/retrieving files from nodes
- Network: a vast tool set for all-purpose network management
- Notification: used for sending push notification to messaging platforms
- Packaging: modules for the usage of most commonly known package managers
- Remote Management Modules: used for managing remote hardware resource pools
- Source Control Modules: used for managing source control providers such as Github, Gitlab and Bitbucket
- Storage Modules: general storage group management
- System Modules: management tools for system specific configuration
- Utilities modules: contains utilities specific for Ansible usage
- Web Infrastructure Modules: used for managing web service related tools
- Windows: 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.
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.
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!
Posted on October 28, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 29, 2024