[BUG] __sls__ variable empty when called with slsutil.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
When an sls file is rendered with the py renderer using salt.slsutil.renderer, the __sls__ variable is empty. According to the py renderer documentation at https://docs.saltproject.io/en/latest/ref/renderers/all/salt.renderers.py.html#module-salt.renderers.py the __sls__ variable should be set to the path of the file:
__sls__- The SLS path of the file. For example, if the root of the base environment is /srv/salt, and the SLS file is /srv/salt/foo/bar/baz.sls, then__sls__in that file will be foo.bar.baz.
Feature Request: really what I would like a simple way to render an sls file in the same directory using a relative path similar to how the path in an jinja import statement can start with the ./ prefix to import a file in the same directory. Example: __salt__.slsutil.renderer("./relative_file.sls)
Setup
-
ec2 instance running rhel 7.9
-
classic packaging (yum install salt-minion)
-
create
/srv/salt/myformula/init.sls:{% set myformula_vars = salt.slsutil.renderer("salt://" ~ tpldir ~ "vars.sls") -
create
/srv/salt/myformula/defaults.sls:my_var_1: value1 my_var_2: value2 -
create
/srv/salt/myformula/vars.sls:#!py import logging from pathlib import Path LOGGER = logging.getLogger(__name__) def run(): logging.info("sls: %s;", __sls__) _slsdir = Path('/'.join(__sls__.split('.')).parent _defaults = __salt__.slsutil.renderer(f"salt://{_slsdir}/defaults.sls)
Steps to Reproduce the behavior
salt-call -l info --local state.apply myformula
Log output is
[INFO ] sls: ;
Expected behavior
__sls__ should be set to the SLS path of the file myformula.vars and the log message should show:
[INFO ] sls: myformula.vars;
Versions Report
salt-call --versions-report
Salt Version:
Salt: 3004.1
Dependency Versions:
Jinja2: 2.11.1
Python: 3.6.8 (default, Aug 13 2020, 07:46:32)
PyYAML: 3.13
System Versions:
dist: rhel 7.9 Maipo
locale: UTF-8
release: 3.10.0-1160.15.2.el7.x86_64
system: Linux
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 salt.slsutil.renderer entry point and the Python renderer behavior used by myformula/init.sls and myformula/vars.sls. Reproduce with salt-call --local state.apply myformula, then verify that rendering sets sls to myformula.vars and supports the requested relative-path behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100