Search code examples
salt-project

State 'pkg.upgrade' found in SLS 'apt-upgrade' is unavailable


I'm trying to build an SLS file that would perform apt-get upgrade call on an Ubuntu system. I am running in masterless mode.

Calling it directly from the command line works:

$ salt-call --local pkg.upgrade
[INFO    ] Executing command 'apt-get -q update' in directory '/root'
[INFO    ] Executing command "dpkg-query --showformat='${Status} ${Package} ${Version} ${Architecture}\n' -W" in directory '/root'
[INFO    ] Executing command ['apt-get', '-q', '-y', '-o', 'DPkg::Options::=--force-confold', '-o', 'DPkg::Options::=--force-confdef', 'dist-upgrade'] in directory '/root'
[INFO    ] Executing command "dpkg-query --showformat='${Status} ${Package} ${Version} ${Architecture}\n' -W" in directory '/root'

However the same call made from an SLS file (YAML format), doesn't work:

# top.sls
base:
  '*':
    - apt-upgrade


# apt-upgrade.sls
apt-upgrade:
  pkg:
    - upgrade


$ salt-call --local state.highstate
# ...
          ID: apt-upgrade
    Function: pkg.upgrade
      Result: False
     Comment: State 'pkg.upgrade' found in SLS 'apt-upgrade' is unavailable
     Started:
    Duration:
     Changes:

Solution

  • The problem you're having is that you haven't understood the difference between execution modules and state modules.

    pkg.upgrade exists in the salt.modules.aptpkg execution module. Thus you can call it from the salt-call command. To use it from a state file however, you'll have to use the module.run state.

    Or better yet, you can see if you find something useful in salt.states.pkg and use that instead.