ansible/docsite/latest/rst/modules.rst

86 lines
2.7 KiB
ReStructuredText
Raw Normal View History

2012-03-08 18:36:47 +00:00
Ansible Modules
===============
2013-03-19 18:46:30 +00:00
.. image:: http://ansible.cc/docs/_static/ansible_fest_2013.png
:alt: ansiblefest 2013
:target: http://ansibleworks.com/fest
2013-03-19 18:46:30 +00:00
2012-08-28 19:41:10 +00:00
.. contents::
2013-05-02 15:35:24 +00:00
:depth: 3
2012-08-28 19:41:10 +00:00
:backlinks: top
Introduction
````````````
2012-08-03 15:31:43 +00:00
Ansible ships with a number of modules (called the 'module library')
that can be executed directly on remote hosts or through :doc:`playbooks`.
Users can also write their own modules. These modules can control system
2012-08-03 15:31:43 +00:00
resources, like services, packages, or files (anything really), or
handle executing system commands.
2012-03-08 18:53:48 +00:00
Let's review how we execute three different modules from the command line::
ansible webservers -m service -a "name=httpd state=running"
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``
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
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
Version 0.8 and higher support the following shorter syntax::
- name: reboot the servers
command: /sbin/reboot -t now
All modules technically return JSON format data, though if you are using the
2012-03-09 19:39:29 +00:00
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
playbooks, these modules can trigger 'change events' in the form of notifying 'handlers'
to run additional tasks.
2012-03-08 18:36:47 +00:00
Documention for each module can be accessed from the command line with the
ansible-doc as well as the man command::
ansible-doc command
man ansible.template
Let's see what's available in the Ansible module library, out of the box:
2012-03-08 18:36:47 +00:00
2012-03-09 19:39:29 +00:00
.. include:: modules/_list.rst
2012-03-22 05:01:02 +00:00
2012-03-09 03:50:00 +00:00
Writing your own modules
2013-05-02 15:31:16 +00:00
````````````````````````
2012-03-08 18:36:47 +00:00
See :doc:`moduledev`.
.. seealso::
:doc:`contrib`
2012-08-07 22:49:10 +00:00
User contributed playbooks, modules, and articles
:doc:`examples`
2012-04-12 22:20:52 +00:00
Examples of using modules in /usr/bin/ansible
:doc:`playbooks`
2012-04-12 22:20:52 +00:00
Examples of using modules with /usr/bin/ansible-playbook
:doc:`moduledev`
How to write your own modules
:doc:`api`
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>`_
Questions? Help? Ideas? Stop by the list on Google Groups
`irc.freenode.net <http://irc.freenode.net>`_
#ansible IRC chat channel