[DOCS] document Module.run usage with pyobjects renderer
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
The new module.run format which will be enforced on the release of 3005 throws a little bit of a monkey wrench in the pyobjects renderer. The new format expects the name of the module to run as one of the keyword arguments, but it can't be listed explicitly in the pyobjects format because of the dot (.) in the name.
Attempting to run something like this:
#!pyobjects
user = ["susan"]
Module.run("pyobject_shadow", shadow.lock_password=user)
will fail with an error like this:
local:
Data failed to compile:
----------
Rendering SLS py_shadow failed, render error: keyword can't be an expression (<string>, line 4)
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 4034, in render_state
context=context,
File "/usr/lib/python3/dist-packages/salt/template.py", line 99, in compile_template
ret = render(input_data, saltenv, sls, **render_kwargs)
File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1201, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1216, in _run_as
return _func_or_method(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/renderers/pyobjects.py", line 495, in render
exec(final_template, _globals)
File "<string>", line 4
SyntaxError: keyword can't be an expression
However, creating a kwargs dictionary seems to work just fine:
#!pyobjects
lock_kwargs = {"shadow.lock_password": ["susan"]}
Module.run("pyobject_shadow", **lock_kwargs)
Suggested Fix
A brief section with code examples such as above should point folks in the right direction.
Location or format of documentation
Might be a good fit in either or both of the pyobjects docs and module.run docs.
Additional context
This probably won't affect many people as I suspect the intersection of people using both pyobjects and module.run is small.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pyobjects documentation and module.run documentation linked in the issue, focusing on their existing usage examples. Add a brief section showing the failing dotted keyword form and the working kwargs-dictionary form, then verify that both examples and the explanation accurately describe the renderer limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100