saltstack / saltstack/salt

[DOCS] document Module.run usage with pyobjects renderer

Open
#61,828 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation help-wanted severity-low time-estimate-sprint
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.