2013-09-29 23:10:28 +00:00
Developing Plugins
2012-03-31 02:28:30 +00:00
==================
2013-12-26 19:32:01 +00:00
.. contents :: Topics
2013-10-06 01:19:19 +00:00
Ansible is pluggable in a lot of other ways separate from inventory scripts and callbacks. Many of these features are there to cover fringe use cases and are infrequently needed, and others are pluggable simply because they are there to implement core features
in ansible and were most convenient to be made pluggable.
2012-03-31 02:28:30 +00:00
2013-10-05 17:50:53 +00:00
This section will explore these features, though they are generally not common in terms of things people would look to extend quite
as often.
2012-08-31 03:55:31 +00:00
2013-10-04 17:27:19 +00:00
.. _developing_connection_type_plugins:
2012-08-31 03:55:31 +00:00
Connection Type Plugins
-----------------------
2014-02-27 23:06:49 +00:00
By default, ansible ships with a 'paramiko' SSH, native ssh (just called 'ssh'), 'local' connection type, and there are also some minor players like 'chroot' and 'jail'. All of these can be used
2012-08-31 03:55:31 +00:00
in playbooks and with /usr/bin/ansible to decide how you want to talk to remote machines. The basics of these connection types
2014-01-11 17:59:03 +00:00
are covered in the :doc: `intro_getting_started` section. Should you want to extend Ansible to support other transports (SNMP? Message bus?
2012-08-31 03:55:31 +00:00
Carrier Pigeon?) it's as simple as copying the format of one of the existing modules and dropping it into the connection plugins
2013-07-04 23:10:28 +00:00
directory. The value of 'smart' for a connection allows selection of paramiko or openssh based on system capabilities, and chooses
2015-09-21 14:59:28 +00:00
'ssh' if OpenSSH supports ControlPersist, in Ansible 1.2.1 and later. Previous versions did not support 'smart'.
2012-07-17 00:57:22 +00:00
2015-09-15 15:57:54 +00:00
More documentation on writing connection plugins is pending, though you can jump into `lib/ansible/plugins/connection <https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/connection> `_ and figure things out pretty easily.
2013-09-29 23:03:51 +00:00
2013-10-04 17:27:19 +00:00
.. _developing_lookup_plugins:
2012-10-16 22:40:01 +00:00
Lookup Plugins
--------------
2012-11-26 23:47:33 +00:00
Language constructs like "with_fileglob" and "with_items" are implemented via lookup plugins. Just like other plugin types, you can write your own.
2015-07-13 15:17:05 +00:00
More documentation on writing lookup plugins is pending, though you can jump into `lib/ansible/plugins/lookup <https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/lookup> `_ and figure
2013-09-29 23:03:51 +00:00
things out pretty easily.
2013-10-04 17:27:19 +00:00
.. _developing_vars_plugins:
2012-11-26 23:47:33 +00:00
Vars Plugins
------------
Playbook constructs like 'host_vars' and 'group_vars' work via 'vars' plugins. They inject additional variable
data into ansible runs that did not come from an inventory, playbook, or command line. Note that variables
can also be returned from inventory, so in most cases, you won't need to write or understand vars_plugins.
2015-01-18 23:55:24 +00:00
More documentation on writing vars plugins is pending, though you can jump into `lib/ansible/inventory/vars_plugins <https://github.com/ansible/ansible/tree/devel/lib/ansible/inventory/vars_plugins> `_ and figure
2013-09-29 23:03:51 +00:00
things out pretty easily.
If you find yourself wanting to write a vars_plugin, it's more likely you should write an inventory script instead.
2013-10-04 17:27:19 +00:00
.. _developing_filter_plugins:
2012-11-26 23:47:33 +00:00
Filter Plugins
--------------
2014-01-11 17:59:03 +00:00
If you want more Jinja2 filters available in a Jinja2 template (filters like to_yaml and to_json are provided by default), they can be extended by writing a filter plugin. Most of the time, when someone comes up with an idea for a new filter they would like to make available in a playbook, we'll just include them in 'core.py' instead.
2013-09-29 23:03:51 +00:00
2015-07-13 15:17:05 +00:00
Jump into `lib/ansible/plugins/filter <https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/filter> `_ for details.
2013-09-29 23:03:51 +00:00
2013-10-04 17:27:19 +00:00
.. _developing_callbacks:
2013-09-29 23:03:51 +00:00
Callbacks
---------
Callbacks are one of the more interesting plugin types. Adding additional callback plugins to Ansible allows for adding new behaviors when responding to events.
2013-10-04 17:27:19 +00:00
.. _callback_examples:
2013-09-29 23:03:51 +00:00
Examples
++++++++
2015-07-13 15:17:05 +00:00
Example callbacks are shown in `lib/ansible/plugins/callback <https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/callback> `_ .
2013-09-29 23:03:51 +00:00
2014-01-11 17:59:03 +00:00
The `log_plays
2015-07-13 15:17:05 +00:00
<https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/log_plays.py> `_
2014-01-11 17:59:03 +00:00
callback is an example of how to intercept playbook events to a log
file, and the `mail
2015-07-13 15:17:05 +00:00
<https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/mail.py> `_
2014-01-11 17:59:03 +00:00
callback sends email when playbooks complete.
2013-09-29 23:03:51 +00:00
2014-01-11 17:59:03 +00:00
The `osx_say
2015-07-13 15:17:05 +00:00
<https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/osx_say.py> `_
2014-01-11 17:59:03 +00:00
callback provided is particularly entertaining -- it will respond with
computer synthesized speech on OS X in relation to playbook events,
and is guaranteed to entertain and/or annoy coworkers.
2013-09-29 23:03:51 +00:00
2013-10-04 17:27:19 +00:00
.. _configuring_callbacks:
2013-09-29 23:03:51 +00:00
Configuring
+++++++++++
2016-03-25 21:08:39 +00:00
To activate a callback drop it in a callback directory as configured in :ref: `ansible.cfg <callback_plugins>` . Plugin load order is alphanumeric in nature. If you have a plugin you want to run first consider naming it `1_first.py` , or if you have a plugin you want to run last consider naming it `z_last.py` .
2013-09-29 23:03:51 +00:00
2013-10-04 17:27:19 +00:00
.. _callback_development:
2013-09-29 23:03:51 +00:00
Development
+++++++++++
2014-01-11 17:59:03 +00:00
More information will come later, though see the source of any of the existing callbacks and you should be able to get started quickly.
2014-05-03 15:59:50 +00:00
They should be reasonably self-explanatory.
2013-09-29 23:03:51 +00:00
2013-10-04 17:27:19 +00:00
.. _distributing_plugins:
2012-10-16 22:40:01 +00:00
Distributing Plugins
--------------------
Plugins are loaded from both Python's site_packages (those that ship with ansible) and a configured plugins directory, which defaults
to /usr/share/ansible/plugins, in a subfolder for each plugin type::
2016-06-22 21:43:09 +00:00
* action
* lookup
* callback
* connection
* filter
* strategy
2016-06-22 21:44:13 +00:00
* cache
* test
* shell
2012-10-16 22:40:01 +00:00
To change this path, edit the ansible configuration file.
In addition, plugins can be shipped in a subdirectory relative to a top-level playbook, in folders named the same as indicated above.
2016-04-27 21:01:20 +00:00
They can also be shipped as part of a role, in a subdirectory named as indicated above. The plugin will be availiable as soon as the role
is called.
2012-03-31 13:29:31 +00:00
.. seealso ::
:doc: `modules`
List of built-in modules
2013-10-05 16:31:16 +00:00
:doc: `developing_api`
Learn about the Python API for task execution
:doc: `developing_inventory`
Learn about how to develop dynamic inventory sources
:doc: `developing_modules`
Learn about how to write Ansible modules
`Mailing List <http://groups.google.com/group/ansible-devel> `_
The development mailing list
2012-03-31 13:55:37 +00:00
`irc.freenode.net <http://irc.freenode.net> `_
#ansible IRC chat channel