Skip to content

Commit 70bf4e4

Browse files
[PR #10071/3249a041 backport][stable-10] Improve MH doc (#10074)
Improve MH doc (#10071) (cherry picked from commit 3249a04) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
1 parent ac89429 commit 70bf4e4

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

docs/docsite/rst/guide_modulehelper.rst

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,18 @@ section above, but there are more elements that will take part in it.
7676
from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
7777
7878
class MyTest(ModuleHelper):
79+
# behavior for module paramaters ONLY, see below for further information
7980
output_params = ()
8081
change_params = ()
8182
diff_params = ()
82-
facts_name = None
8383
facts_params = ()
84+
85+
facts_name = None # used if generating facts, from parameters or otherwise
86+
87+
# transitional variables for the new VarDict implementation, see information below
8488
use_old_vardict = True
8589
mute_vardict_deprecation = False
90+
8691
module = dict(
8792
argument_spec=dict(...),
8893
# ...
@@ -211,9 +216,10 @@ One of the attributes in that metadata marks the variable for output, and MH mak
211216
There are two ways to prevent that from happening:
212217

213218
#. Set ``mute_vardict_deprecation = True`` and the deprecation will be silenced. If the module still uses the old ``VarDict``,
214-
it will not be able to update to community.general 11.0.0 (Spring 2026) upon its release.
215-
#. Set ``use_old_vardict = False`` to make the MH module use the new ``VarDict`` immediatelly.
216-
The new ``VarDict`` and its use is documented and this is the recommended way to handle this.
219+
it will not be able to update to community.general 11.0.0 (Spring 2025) upon its release.
220+
#. Set ``use_old_vardict = False`` to make the MH module use the new ``VarDict`` immediately.
221+
We strongly recommend you use the new ``VarDict``, for that you make sure to consult its documentation at
222+
:ref:`ansible_collections.community.general.docsite.guide_vardict`.
217223

218224
.. code-block:: python
219225
@@ -233,6 +239,11 @@ If you want to include some module parameters in the output, list them in the ``
233239
output_params = ('state', 'name')
234240
...
235241
242+
.. important::
243+
244+
The variable names listed in ``output_params`` **must be module parameters**, as in parameters listed in the module's ``argument_spec``.
245+
Names not found in ``argument_spec`` are silently ignored.
246+
236247
Another neat feature provided by MH by using ``VarDict`` is the automatic tracking of changes when setting the metadata ``change=True``.
237248
Again, to enable this feature for module parameters, you must list them in the ``change_params`` class variable.
238249

@@ -243,6 +254,11 @@ Again, to enable this feature for module parameters, you must list them in the `
243254
change_params = ('value', )
244255
...
245256
257+
.. important::
258+
259+
The variable names listed in ``change_params`` **must be module parameters**, as in parameters listed in the module's ``argument_spec``.
260+
Names not found in ``argument_spec`` are silently ignored.
261+
246262
.. seealso::
247263

248264
See more about this in
@@ -260,6 +276,11 @@ With that, MH will automatically generate the diff output for variables that hav
260276
# example from community.general.gio_mime
261277
self.vars.set_meta("handler", initial_value=gio_mime_get(self.runner, self.vars.mime_type), diff=True, change=True)
262278
279+
.. important::
280+
281+
The variable names listed in ``diff_params`` **must be module parameters**, as in parameters listed in the module's ``argument_spec``.
282+
Names not found in ``argument_spec`` are silently ignored.
283+
263284
Moreover, if a module is set to return *facts* instead of return values, then again use the metadata ``fact=True`` and ``fact_params`` for module parameters.
264285
Additionally, you must specify ``facts_name``, as in:
265286

@@ -283,6 +304,11 @@ That generates an Ansible fact like:
283304
debug:
284305
msg: Volume fact is {{ ansible_facts.volume_facts.volume }}
285306

307+
.. important::
308+
309+
The variable names listed in ``fact_params`` **must be module parameters**, as in parameters listed in the module's ``argument_spec``.
310+
Names not found in ``argument_spec`` are silently ignored.
311+
286312
.. important::
287313

288314
If ``facts_name`` is not set, the module does not generate any facts.

0 commit comments

Comments
 (0)