2016-09-23 20:48:37 +00:00
Developing Modules
==================
.. contents :: Topics
2017-01-27 22:03:26 +00:00
.. _module_dev_welcome:
Welcome
`` ` ` ` ``
This section discusses how to develop, debug, review, and test modules.
2016-09-23 20:48:37 +00:00
Ansible modules are reusable, standalone scripts that can be used by the Ansible API,
or by the :command: `ansible` or :command: `ansible-playbook` programs. They
return information to ansible by printing a JSON string to stdout before
2017-04-23 07:47:03 +00:00
exiting. They take arguments in one of several ways which we'll go into
2016-09-23 20:48:37 +00:00
as we work through this tutorial.
2017-01-07 19:38:52 +00:00
See :doc: `../modules` for a list of existing modules.
2016-09-23 20:48:37 +00:00
Modules can be written in any language and are found in the path specified
2017-03-05 11:41:29 +00:00
by :envvar: `ANSIBLE_LIBRARY` or the `` --module-path `` command line option or
2017-04-23 07:47:03 +00:00
in the `library section of the Ansible configuration file <http://docs.ansible.com/ansible/intro_configuration.html#library> `_ .
2016-09-23 20:48:37 +00:00
2017-01-27 22:03:26 +00:00
.. _module_dev_should_you:
2016-09-23 20:48:37 +00:00
2017-01-27 22:03:26 +00:00
Should You Develop A Module?
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
2017-03-05 11:41:29 +00:00
Before diving into the work of creating a new module, you should think about whether you actually *should*
2017-01-27 22:03:26 +00:00
develop a module. Ask the following questions:
2016-09-23 20:48:37 +00:00
2017-03-05 11:41:29 +00:00
1. Does a similar module already exist?
2016-09-23 20:48:37 +00:00
2017-06-30 19:16:26 +00:00
There are a lot of existing modules available, you should check out the list of existing modules at :doc: `../modules`
2016-09-23 20:48:37 +00:00
2017-06-30 19:16:26 +00:00
2. Has someone already worked on a similar Pull Request?
It's possible that someone has already started developing a similar PR. There are a few ways to find open module Pull Requests:
* `GitHub new module PRs <https://github.com/ansible/ansible/labels/new_module> `_
* `All updates to modules <https://github.com/ansible/ansible/labels/module> `_
* `New module PRs listed by directory <https://ansible.sivel.net/pr/byfile.html> `_ search for `lib/ansible/modules/`
If you find an existing PR that looks like it addresses the issue you are trying to solve, please provide feedback on the PR - this will speed up getting the PR merged.
3. Should you use or develop an action plugin instead?
2016-09-23 20:48:37 +00:00
2017-03-05 11:41:29 +00:00
Action plugins get run on the master instead of on the target. For modules like file/copy/template, some of the work needs to be done on the master before the module executes on the target. Action plugins execute first on the master and can then execute the normal module on the target if necessary.
2016-09-23 20:48:37 +00:00
2017-06-06 21:39:48 +00:00
For more information about action plugins, `read the action plugins documentation here <https://docs.ansible.com/ansible/dev_guide/developing_plugins.html> `_ .
2016-09-23 20:48:37 +00:00
2017-06-30 19:16:26 +00:00
4. Should you use a role instead?
2016-09-23 20:48:37 +00:00
2017-06-06 21:39:48 +00:00
Check out the roles documentation `available here <http://docs.ansible.com/ansible/playbooks_reuse_roles.html#roles> `_ .
2017-03-05 11:41:29 +00:00
2016-09-23 20:48:37 +00:00
2017-01-27 22:03:26 +00:00
.. _developing_modules_all:
2016-09-23 20:48:37 +00:00
2017-01-27 22:03:26 +00:00
How To Develop A Module
2016-09-23 20:48:37 +00:00
`` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ``
2017-01-27 22:03:26 +00:00
The following topics will discuss how to develop and work with modules:
2017-01-19 11:25:28 +00:00
2017-01-27 22:03:26 +00:00
:doc: `developing_modules_general`
2017-02-10 22:02:24 +00:00
A general overview of how to develop, debug, and test modules.
2017-07-31 22:02:56 +00:00
:doc: `developing_modules_general_windows`
A general overview of how to develop, debug and test Windows modules.
2017-01-27 22:03:26 +00:00
:doc: `developing_modules_documenting`
How to include in-line documentation in your module.
:doc: `developing_modules_best_practices`
Best practices, recommendations, and things to avoid.
:doc: `developing_modules_checklist`
Checklist for contributing your module to Ansible.
2017-04-28 08:08:26 +00:00
:doc: `testing`
Developing unit and integration tests.
2017-04-04 18:18:19 +00:00
:doc: `developing_python3`
2017-03-17 01:49:29 +00:00
Adding Python 3 support to modules (all new modules must be Python-2.6 and Python-3.5 compatible).
2017-02-10 22:02:24 +00:00
:doc: `developing_modules_in_groups`
A guide for partners wanting to submit multiple modules.
2016-09-23 20:48:37 +00:00
.. seealso ::
2017-01-07 19:38:52 +00:00
:doc: `../modules`
2016-09-23 20:48:37 +00:00
Learn about available modules
:doc: `developing_plugins`
Learn about developing plugins
:doc: `developing_api`
Learn about the Python API for playbook and task execution
2017-01-27 22:03:26 +00:00
`GitHub modules directory <https://github.com/ansible/ansible/tree/devel/lib/ansible/modules> `_
Browse module source code
2016-09-23 20:48:37 +00:00
`Mailing List <http://groups.google.com/group/ansible-devel> `_
Development mailing list
`irc.freenode.net <http://irc.freenode.net> `_
#ansible IRC chat channel
2016-10-14 19:18:04 +00:00
.. include :: ./developing_module_utilities.rst