You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Updated developer guide for module development to work with
collection and PYTHONPATH
Fixes: ansible#2374
Signed-off-by: Abhijeet Kasurde <[email protected]>
Copy file name to clipboardexpand all lines: docs/docsite/rst/dev_guide/developing_modules_general.rst
+26-5
Original file line number
Diff line number
Diff line change
@@ -26,18 +26,27 @@ Modules for inclusion in Ansible itself must be Python or Powershell.
26
26
One advantage of using Python or Powershell for your custom modules is being able to use the ``module_utils`` common code that does a lot of the
27
27
heavy lifting for argument processing, logging and response writing, among other things.
28
28
29
-
Creating a module
30
-
=================
29
+
Creating a standalone module
30
+
============================
31
31
32
32
It is highly recommended that you use a ``venv`` or ``virtualenv`` for Python development.
33
33
34
-
To create a module:
34
+
To create a standalone module:
35
35
36
36
1. Create a ``library`` directory in your workspace. Your test play should live in the same directory.
37
37
2. Create your new module file: ``$ touch library/my_test.py``. Or just open/create it with your editor of choice.
38
38
3. Paste the content below into your new module file. It includes the :ref:`required Ansible format and documentation <developing_modules_documenting>`, a simple :ref:`argument spec for declaring the module options <argument_spec>`, and some example code.
39
39
4. Modify and extend the code to do what you want your new module to do. See the :ref:`programming tips <developing_modules_best_practices>` and :ref:`Python 3 compatibility <developing_python_3>` pages for pointers on writing clean and concise module code.
40
40
41
+
Creating a module in a collection
42
+
=================================
43
+
44
+
To create a new module in an existing collection called ``foo.bar``:
45
+
46
+
1. Create your new module file: ``$ touch <PATH_TO_COLLECTION>/ansible_collections/foo/bar/plugins/modules/my_test.py``. Or just create it with your editor of choice.
47
+
2. Paste the content below into your new module file. It includes the :ref:`required Ansible format and documentation <developing_modules_documenting>`, a simple :ref:`argument spec for declaring the module options <argument_spec>`, and some example code.
48
+
3. Modify and extend the code to do what you want your new module to do. See the :ref:`programming tips <developing_modules_best_practices>` and :ref:`Python 3 compatibility <developing_python_3>` pages for pointers on writing clean and concise module code.
0 commit comments