Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Environment specific salt modules #66495

Open
jtraub91 opened this issue May 9, 2024 · 2 comments
Open

[FEATURE REQUEST] Environment specific salt modules #66495

jtraub91 opened this issue May 9, 2024 · 2 comments
Labels
Feature new functionality including changes to functionality and code refactors, etc. needs-triage

Comments

@jtraub91
Copy link
Contributor

jtraub91 commented May 9, 2024

Is your feature request related to a problem? Please describe.
Salt's fileserver has a concept of environments, which can work decently well to isolate different versions of states and other files to operate on minions under different circumstances. Salt even includes the ability to set the default saltenv and/or lock_saltenv in the minion config. However, one aspect in which this falls short is when you have custom modules in different environments. Currently the minion does not have a concept of a version of a module per environment, and is simply the last one synced to the minion's cache wins. This is especially strange, since salt supports and defaults to syncing modules from multiple environments via the saltutil.sync_modules command. This default behavior does not make sense in the scenario where different versions of modules of the same name exist in multiple environments. The problem is that this could prevent sharing masters / minions in the scenario where they are running jobs simultaneously with different modules for different "environments", in production or development scenarios.

Describe the solution you'd like
The solution to this could simply be to have a directory in the minion's module cache, per environment, that it would use based on the saltenv that is active for a given command.

Describe alternatives you've considered
There does not seem to be a way to allow for simultaneous executions on the same minion with different salt environments specified specifically when they are attempting to use different versions of the the same module in the different environments, due to the fact that only one can be cached on the minion at a single time.

@jtraub91 jtraub91 added Feature new functionality including changes to functionality and code refactors, etc. needs-triage labels May 9, 2024
@jtraub91
Copy link
Contributor Author

jtraub91 commented May 9, 2024

Consider the following setup:

Master and minion on a single VM.

# /etc/salt/master.d/master.conf
user: root
file_roots:
  base:
    - /srv/salt/base
  dev:
    - /srv/salt/dev
# /etc/salt/minion.d/minion.conf
master: localhost
# /srv/salt/base/echo_module.sls
echo_base:
  cmd.run:
    - name: echo {{ salt.env.tag() }}
# /srv/salt/dev/echo_module.sls
echo_dev:
  cmd.run:
    - name: echo {{ salt.env.tag() }}
# /srv/salt/base/_modules/env.py
def tag():
    return "base_tag"
# /srv/salt/dev/_modules/env.py
def tag():
    return "dev_tag"
# /srv/salt/base/top.sls
base:
  "*":
    - echo_module

dev:
  "*":
    - echo_module
# /srv/salt/dev/top.sls
base:
  "*":
    - echo_module

dev:
  "*":
    - echo_module

Now after syncing modules, both environments will be synced because they are both defined in the top file

# salt \* saltutil.sync_modules
salt-modules-env:
    - modules.env
    - modules.env

And thus only whichever module got cached last will be the one in use, even when specifying different saltenv during the state calls.

root@salt-modules-env:~# salt \* state.sls echo_module saltenv=base
salt-modules-env:
----------
          ID: echo_base
    Function: cmd.run
        Name: echo dev_tag
      Result: True
     Comment: Command "echo dev_tag" run
     Started: 15:53:34.263269
    Duration: 9.128 ms
     Changes:   
              ----------
              pid:
                  12415
              retcode:
                  0
              stderr:
              stdout:
                  dev_tag

Summary for salt-modules-env
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:   9.128 ms
root@salt-modules-env:~# salt \* state.sls echo_module saltenv=dev
salt-modules-env:
----------
          ID: echo_dev
    Function: cmd.run
        Name: echo dev_tag
      Result: True
     Comment: Command "echo dev_tag" run
     Started: 15:53:40.182158
    Duration: 18.539 ms
     Changes:   
              ----------
              pid:
                  12535
              retcode:
                  0
              stderr:
              stdout:
                  dev_tag

Summary for salt-modules-env
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:  18.539 ms

This feature request is suggesting to have salt use the correct module during each state call, respectively, based on the saltenv specified.

@max-arnold
Copy link
Contributor

Have you tried something like that https://salt.tips/patching-salt-modules/#version-aware-override

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature new functionality including changes to functionality and code refactors, etc. needs-triage
Projects
None yet
Development

No branches or pull requests

2 participants