modules.rst 2.28 KB
Newer Older
1 2
About Modules
=============
Michael DeHaan committed
3

4
.. toctree::
5
   :maxdepth: 4
6

7 8
.. _modules_intro:

9 10 11
Introduction
````````````

Mark Theunissen committed
12
Ansible ships with a number of modules (called the 'module library')
13
that can be executed directly on remote hosts or through :doc:`Playbooks <playbooks>`.
14 15

Users can also write their own modules.   These modules can control system resources, like services, packages, or files (anything really), or
Mark Theunissen committed
16
handle executing system commands.
17

18 19
Let's review how we execute three different modules from the command line::

20
    ansible webservers -m service -a "name=httpd state=started"
21 22 23
    ansible webservers -m ping
    ansible webservers -m command -a "/sbin/reboot -t now"

Mark Theunissen committed
24
Each module supports taking arguments.  Nearly all modules take ``key=value``
25 26
arguments, space delimited.  Some modules take no arguments, and the command/shell modules simply 
take the string of the command you want to run.
Michael DeHaan committed
27

28 29 30
From playbooks, Ansible modules are executed in a very similar way::

    - name: reboot the servers
Mark Theunissen committed
31
      action: command /sbin/reboot -t now
32

Mikhail Sobolev committed
33
Which can be abbreviated to::
34 35 36 37

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

38 39
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.
Michael DeHaan committed
40

41
Modules are `idempotent`, meaning they will seek to avoid changes to the system unless a change needs to be made.  When using Ansible
42
playbooks, these modules can trigger 'change events' in the form of notifying 'handlers' to run additional tasks.
43

44
Documentation for each module can be accessed from the command line with the ansible-doc tool::
Michael DeHaan committed
45

46
    ansible-doc yum
47 48 49

.. seealso::

50
   :doc:`intro_adhoc`
Martijn Koster committed
51
       Examples of using modules in /usr/bin/ansible
52
   :doc:`playbooks`
Martijn Koster committed
53
       Examples of using modules with /usr/bin/ansible-playbook
54
   :doc:`developing_modules`
55
       How to write your own modules
56
   :doc:`developing_api`
57
       Examples of using modules with the Python API
Martijn Koster committed
58
   `Mailing List <http://groups.google.com/group/ansible-project>`_
59 60 61 62
       Questions? Help? Ideas?  Stop by the list on Google Groups
   `irc.freenode.net <http://irc.freenode.net>`_
       #ansible IRC chat channel