salt: Release notes for v3000 do not mention changes to `slspath` variable

Description of Issue

Release notes for v3000 do not mention changes to slspath variable by #55434 / #55433 , which previously returned the parent directory instead of the path to the state file itself.

This functionality appears to be covered by the tpldir variable, but this is not documented on https://docs.saltstack.com/en/latest/ref/states/vars.html.

Can both the v3000 release notes and the SLS Template Variable Reference be updated to make this more visible to others?

Setup

Tree:

/srv/salt/users/
|-- files
|   |-- bash_profile
|   |-- bashrc
|   |-- login.defs
|   |-- root_profile
|   `-- vimrc
|-- init.sls
|-- root.sls
`-- staff.sls

root.sls

/root/.bashrc:
  file.managed:
    - source: salt://{{ slspath }}/files/bashrc
    - template: jinja
    - defaults:
        sls: {{ sls }}

Steps to Reproduce Issue

  1. Apply users.root state

Output:

----------
          ID: /root/.bashrc
    Function: file.managed
      Result: False
     Comment: Source file salt://users/root/files/bashrc not found in saltenv 'base'
     Started: 20:46:08.752499
    Duration: 2.315 ms
     Changes:   
----------

Replacing slspath with tpldir resolves the issue, but this is not an obvious fix.

Versions Report

Salt Version:
           Salt: 3000
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
       M2Crypto: 0.33.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: 3.7.3
         pygit2: Not Installed
         Python: 3.6.8 (default, Aug  7 2019, 17:28:10)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4
 
System Versions:
           dist: centos 7.7.1908 Core
         locale: ANSI_X3.4-1968
        machine: x86_64
        release: 3.10.0-1062.9.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.7.1908 Core

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 10
  • Comments: 25 (20 by maintainers)

Commits related to this issue

Most upvoted comments

For tpldir not being documented: #50925

@dhs-rec And some people are expecting slspath to work as documented. Before, tpldir and slspath did the same thing, and that’s clearly not the intent. In addition, it deprives people of a means to get the path of the SLS file.

Since this has gone completely undocumented AND is a backwards incompatible change, I’d vote for reverting it to the previous behaviour and only then announce it as being deprecated and change it in the second next release. Nothing else does make any sense.

A quick patch:

patches/slspath.sls:

{% if grains.saltversion == "3000" %}
patch:
  pkg.installed

slspath_patch:
  file.patch:
    - name: '{{ grains.saltpath }}'
    - source: salt://patches/files/3000-slspath.diff
    - strip: 2
    - require:
        - pkg: patch

restart_salt_minion:
  cmd.run:
    - name: 'salt-call service.restart salt-minion'
    - bg: true
    - onchanges:
      - file: slspath_patch
{%- endif %}

patches/files/3000-slspath.diff:

diff --git a/salt/utils/templates.py b/salt/utils/templates.py
index d026118269..98092a9d79 100644
--- a/salt/utils/templates.py
+++ b/salt/utils/templates.py
@@ -122,6 +122,8 @@ def wrap_tmpl_func(render_str):
             slspath = context['sls'].replace('.', '/')
             if tmplpath is not None:
                 context['tplpath'] = tmplpath
+                if not tmplpath.lower().replace('\\', '/').endswith('/init.sls'):
+                    slspath = os.path.dirname(slspath)
                 template = tmplpath.replace('\\', '/')
                 i = template.rfind(slspath.replace('.', '/'))
                 if i != -1:

Run sudo salt MINION state.apply patches.slspath to apply the fix.

Another thing I noticed about this change is it made things in-consistent. With the change, running state with the foo/init.sls would return still return the directory where the init.sls is located foo. Running a state within a directory foo/bat.sls wougld return foo/bat.

When the change is reverted both of the above scenarios return foo. Overall, I think the name slspath is very misleading and should be addressed. Perhaps by deprecating it all together and making slsdir instead. I could also see a case for adding slsdir and changing slspath to reflect the actual path (including the file extension).

In any case, for the 3000.1 release, I have reverted the change and updated the documentation for slspath to more accurately reflect the behavior.

Yeah, I agree. The correct move here is to build out the documentation, not to break slspath again.

EDIT: I’ve changed my mind, see below.

I don’t understand how is this going to be resolved. Is the change to slspath value going to become permanent (in which case I need to replace slspath variable with tpldir everywhere) or it’s going to be reverted to the previous value (in which case I just need to wait for the next salt release)?

The commit: https://github.com/saltstack/salt/commit/5a17dd6390aa8ef9a7f6899e6d9ce8be2b6750f3#diff-96d7010eb773dc57ad2c8eb89cd12807

As all (relevant) unittests reported success, it may be a good idea to harden the variables with unittests.

+1. Sure do love these breaking changes.

Add me a +1. This breaks previously working SLS files and it is frustrating to have this happen with ZERO indication.