[BUG] Error when using git commit hash as a saltenv when running states
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
In the documentation, it is mentioning that we can use sha as git_ref_type and hence using a commit hash as a saltenv/pillarenv. The issue is that, we can see sha is working correctly when doing something like
salt-run fileserver.file_list backend=git saltenv=<sha>
but it fails with environment does not exist when trying to use the sha as saltenv when running states:
# salt-call state.apply <state_name> saltenv=<commit_hash>
[ERROR ] Nonexistent saltenv <commit_hash> found in include of '<state_name.included_state_name>' within SLS '<commit_hash>:<state_name>'
/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/psutil_compat.py:16: DeprecationWarning: Please stop importing 'salt.utils.psutil_compat' and instead import 'psutil' directly as there's no longer a need for a compatability layer. The 'salt.utils.psutil_compat' will go away on Salt 3008.0 (Argon).
salt.utils.versions.warn_until(
local:
Data failed to compile:
----------
No matching salt environment for environment '<commit_hash>' found
----------
Nonexistent saltenv '<commit_hash>' found in include of '<state_name.included_state_name>' within SLS '<commit_hash>:<state_name>'
Setup
Amazon Linux 2 salt master, configured with git repository for states and pillar data.
- on-prem machine
- VM (Virtualbox, KVM, etc. please specify)
- VM running on a cloud service, please be explicit and add details
- container (Kubernetes, Docker, containerd, etc. please specify)
- or a combination, please be explicit
- jails if it is FreeBSD
- classic packaging
- onedir packaging
- used bootstrap to install
Steps to Reproduce the behavior
Master gitfs config
gitfs_remotes:
- ssh://git@xxxxxxxxxxxxxxxxx/repo.git
gitfs_root: states
gitfs_pubkey: xxxxxxxxxxxxxxxx
gitfs_privkey: xxxxxxxxxxxxxxxx
gitfs_update_interval: 60
fileserver_backend:
- git
top_file_merging_strategy: same
to reproduce, try to run the state from minion using:
salt-call state.apply <state_name> saltenv=<commit_hash>
or from master using:
salt '*' state.apply <state_name> saltenv=<commit_hash>
Expected behavior
state pulled from <commit_hash> from the states git repository configured in gitfs
Actual behavior
Error that saltenv called <commit_hash> does not exist
Versions Report
Salt Version:
Salt: 3006.9
Python Version:
Python: 3.10.14 (main, Jun 26 2024, 11:44:37) [GCC 11.2.0]
Dependency Versions:
cffi: 1.17.1
cherrypy: unknown
cryptography: 42.0.5
dateutil: 2.8.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.1.4
libgit2: 1.7.1
looseversion: 1.0.2
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.2
msgpack-pure: Not Installed
mysql-python: Not Installed
packaging: 22.0
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.19.1
pygit2: 1.14.0
python-gnupg: 0.4.8
PyYAML: 6.0.1
PyZMQ: 23.2.0
relenv: 0.17.0
smmap: Not Installed
timelib: 0.2.4
Tornado: 4.5.3
ZMQ: 4.3.4
System Versions:
dist: amzn 2
locale: utf-8
machine: x86_64
release: 5.10.230-223.885.amzn2.x86_64
system: Linux
version: Amazon Linux 2
Additional context
Can we have an understanding if this is a bug or the assumption that commit hashes can be used a salt environment is wrong? If this is a bug can we have it fixed? It will be really helpful to have the states/pillars versioned this way a system can get configured from a specific commit instead of always relying on latest commit hash from branch/tag. If this is the expected behavior, I believe we should update the documentation to mention this as it may cause confusion.
Thank you
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 gitfs_ref_types documentation and reproduce the difference between salt-run fileserver.file_list backend=git saltenv=<commit_hash> and state.apply ... saltenv=<commit_hash>. Trace saltenv handling during state compilation, especially included SLS files, and verify that a commit hash works consistently or that the documentation clearly states the limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, 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