2018-03-14 20:44:21 +01:00
.. _intro_modules:
2015-07-17 19:53:13 +02:00
Introduction
============
2018-06-07 22:17:20 +02:00
Modules (also referred to as "task plugins" or "library plugins") are discrete units of code that can be used from the command line or in a playbook task.
2015-07-17 19:53:13 +02:00
Let's review how we execute three different modules from the command line::
ansible webservers -m service -a "name=httpd state=started"
ansible webservers -m ping
ansible webservers -m command -a "/sbin/reboot -t now"
Each module supports taking arguments. Nearly all modules take `` key=value ``
arguments, space delimited. Some modules take no arguments, and the command/shell modules simply
take the string of the command you want to run.
From playbooks, Ansible modules are executed in a very similar way::
- name: reboot the servers
action: command /sbin/reboot -t now
Which can be abbreviated to::
- name: reboot the servers
command: /sbin/reboot -t now
Another way to pass arguments to a module is using yaml syntax also called 'complex args' ::
- name: restart webserver
service:
name: httpd
state: restarted
All modules technically return JSON format data, though if you are using the command line or playbooks, you don't really need to know much about
that. If you're writing your own module, you care, and this means you do not have to write modules in any particular language -- you get to choose.
2016-12-01 23:32:55 +01:00
Modules should be idempotent, and should avoid making any changes if
they detect that the current state matches the desired final state. When using
Ansible playbooks, these modules can trigger 'change events' in the form of
notifying 'handlers' to run additional tasks.
2015-07-17 19:53:13 +02:00
Documentation for each module can be accessed from the command line with the ansible-doc tool::
ansible-doc yum
2019-06-26 23:07:27 +02:00
For a list of all available modules, see the :ref: `Module Docs <modules_by_category>` , or run the following at a command prompt::
2015-07-17 19:53:13 +02:00
ansible-doc -l
.. seealso ::
2018-03-14 20:44:21 +01:00
:ref: `intro_adhoc`
2015-07-17 19:53:13 +02:00
Examples of using modules in /usr/bin/ansible
2018-03-14 20:44:21 +01:00
:ref: `working_with_playbooks`
2015-07-17 19:53:13 +02:00
Examples of using modules with /usr/bin/ansible-playbook
2018-03-14 20:44:21 +01:00
:ref: `developing_modules`
2015-07-17 19:53:13 +02:00
How to write your own modules
2018-03-14 20:44:21 +01:00
:ref: `developing_api`
2015-07-17 19:53:13 +02:00
Examples of using modules with the Python API
2018-07-21 15:48:47 +02:00
`Mailing List <https://groups.google.com/group/ansible-project> `_
2015-07-17 19:53:13 +02:00
Questions? Help? Ideas? Stop by the list on Google Groups
`irc.freenode.net <http://irc.freenode.net> `_
#ansible IRC chat channel