2013-12-25 18:23:58 +00:00
|
|
|
About Modules
|
|
|
|
=============
|
2012-03-08 18:36:47 +00:00
|
|
|
|
2013-12-24 23:05:41 +00:00
|
|
|
.. toctree::
|
2013-12-24 23:51:46 +00:00
|
|
|
:maxdepth: 4
|
2013-12-24 23:05:41 +00:00
|
|
|
|
2013-10-04 22:34:39 +00:00
|
|
|
.. _modules_intro:
|
|
|
|
|
2012-08-28 19:41:10 +00:00
|
|
|
Introduction
|
|
|
|
````````````
|
|
|
|
|
2012-08-03 15:31:43 +00:00
|
|
|
Ansible ships with a number of modules (called the 'module library')
|
2013-11-11 18:23:03 +00:00
|
|
|
that can be executed directly on remote hosts or through :doc:`Playbooks <playbooks>`.
|
2013-12-25 18:23:58 +00:00
|
|
|
|
|
|
|
Users can also write their own modules. These modules can control system resources, like services, packages, or files (anything really), or
|
2012-08-03 15:31:43 +00:00
|
|
|
handle executing system commands.
|
2012-03-08 18:53:48 +00:00
|
|
|
|
2012-03-31 14:38:24 +00:00
|
|
|
Let's review how we execute three different modules from the command line::
|
|
|
|
|
2014-04-08 14:45:55 +00:00
|
|
|
ansible webservers -m service -a "name=httpd state=started"
|
2012-03-31 14:38:24 +00:00
|
|
|
ansible webservers -m ping
|
|
|
|
ansible webservers -m command -a "/sbin/reboot -t now"
|
|
|
|
|
2012-08-03 15:31:43 +00:00
|
|
|
Each module supports taking arguments. Nearly all modules take ``key=value``
|
2013-12-25 18:23:58 +00:00
|
|
|
arguments, space delimited. Some modules take no arguments, and the command/shell modules simply
|
|
|
|
take the string of the command you want to run.
|
2012-03-09 03:50:00 +00:00
|
|
|
|
2012-03-31 14:38:24 +00:00
|
|
|
From playbooks, Ansible modules are executed in a very similar way::
|
|
|
|
|
|
|
|
- name: reboot the servers
|
2012-08-03 15:31:43 +00:00
|
|
|
action: command /sbin/reboot -t now
|
2012-03-31 14:38:24 +00:00
|
|
|
|
2013-12-25 19:08:14 +00:00
|
|
|
Which can be abbreviated to::
|
2012-10-23 13:14:01 +00:00
|
|
|
|
|
|
|
- name: reboot the servers
|
|
|
|
command: /sbin/reboot -t now
|
|
|
|
|
2013-12-25 18:23:58 +00:00
|
|
|
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.
|
2012-03-08 18:36:47 +00:00
|
|
|
|
2012-08-01 03:19:41 +00:00
|
|
|
Modules are `idempotent`, meaning they will seek to avoid changes to the system unless a change needs to be made. When using Ansible
|
2013-12-25 18:23:58 +00:00
|
|
|
playbooks, these modules can trigger 'change events' in the form of notifying 'handlers' to run additional tasks.
|
2012-03-22 05:01:02 +00:00
|
|
|
|
2013-12-25 18:23:58 +00:00
|
|
|
Documentation for each module can be accessed from the command line with the ansible-doc tool::
|
2012-03-08 18:36:47 +00:00
|
|
|
|
2013-12-25 18:23:58 +00:00
|
|
|
ansible-doc yum
|
2012-03-31 13:29:31 +00:00
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
2013-09-29 23:16:59 +00:00
|
|
|
:doc:`intro_adhoc`
|
2012-04-12 22:20:52 +00:00
|
|
|
Examples of using modules in /usr/bin/ansible
|
2012-03-31 13:29:31 +00:00
|
|
|
:doc:`playbooks`
|
2012-04-12 22:20:52 +00:00
|
|
|
Examples of using modules with /usr/bin/ansible-playbook
|
2013-09-29 23:16:59 +00:00
|
|
|
:doc:`developing_modules`
|
2012-03-31 14:21:28 +00:00
|
|
|
How to write your own modules
|
2013-09-29 23:30:10 +00:00
|
|
|
:doc:`developing_api`
|
2012-03-31 13:29:31 +00:00
|
|
|
Examples of using modules with the Python API
|
2012-04-12 22:20:52 +00:00
|
|
|
`Mailing List <http://groups.google.com/group/ansible-project>`_
|
2012-03-31 13:55:37 +00:00
|
|
|
Questions? Help? Ideas? Stop by the list on Google Groups
|
|
|
|
`irc.freenode.net <http://irc.freenode.net>`_
|
|
|
|
#ansible IRC chat channel
|
|
|
|
|