saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.21k stars 5.48k forks source link

win_pkg : Salt+Windows only sees the latest package when using repong #36302

Closed stjack99 closed 5 years ago

stjack99 commented 8 years ago

Description of Issue/Question

Note: I've only tested this using win/repo-ng

I have a repo defined with >= 2 items in it. Salt-call pkg.available_version will only show the latest version as being available. Pkg.list_available lists both versions as being available.

If I have version 1 installed, enable version 2 in the repo, and pkg.install the 2nd, both versions get installed. Salt does not try to uninstall the old one first. I wrote a state that first uninstalls version 1, then install version two, but the uninstall state says that version 1 isn't installed even though I've specified it should uninstall version 1.

It looks like Salt will only recognize the latest version. So, when it's time to install version 2, it doesn't care about version 1, doesn't see it, and doesn't uninstall it first.

Setup

repo-ng/app.sls app: {% for version in (('18.2.22'), ('18.2.28')) %} '{{ version }}': full_name: 'Clunky Application' installer: 'http://herp.derp.com/installs/app/{{ version }}/appInstaller.exe' installer: 'http://herp.derp.com/installs/app/{{ version }}/appInstaller.exe' install_flags: '/s /v"/qn"' uninstall_flags: '/s /x /v"/qn"' msiexec: False locale: en_US reboot: False {% endfor %}

states/app.sls app-install: pkg.installed:

app-remove-old-versions: pkg.removed:

Note: 18.2.22 is installed and is shown correctly in pkg.list_pkgs

When I execute the app state, I get:

salt-call state.sls app [ERROR ] app None not installed local:

  app:
      ----------
      current:
          18.2.28 not installed

Also, If I do a pkg.remove, I get [ERROR ] app None not installed local:

  app:
      ----------
      current:
          18.2.28 not installed

Versions Report

Master Salt Version: Salt: 2016.3.2

Dependency Versions: cffi: 1.7.0 cherrypy: 3.2.2 dateutil: 2.5.0 gitdb: 0.6.4 gitpython: Not Installed ioflo: Not Installed Jinja2: 2.8 libgit2: 0.23.4 libnacl: Not Installed M2Crypto: 0.24.0 Mako: Not Installed msgpack-pure: Not Installed msgpack-python: 0.4.7 mysql-python: Not Installed pycparser: 2.10 pycrypto: 2.6.1 pygit2: 0.23.2 Python: 2.7.12 (default, Jul 26 2016, 12:56:51) python-gnupg: Not Installed PyYAML: 3.11 PyZMQ: 15.3.0 RAET: Not Installed smmap: 0.9.0 timelib: Not Installed Tornado: 4.4.1 ZMQ: 4.1.5

System Versions: dist:
machine: amd64 release: 10.3-RELEASE-p7 system: FreeBSD version: Not Installed

Minion Versions tested: 2016.3.2, 2016.3.3 Salt Version: Salt: 2016.3.3

Dependency Versions: cffi: 1.6.0 cherrypy: 5.3.0 dateutil: 2.5.3 gitdb: 0.6.4 gitpython: 2.0.2 ioflo: 1.5.3 Jinja2: 2.8 libgit2: Not Installed libnacl: 1.4.5 M2Crypto: Not Installed Mako: 1.0.4 msgpack-pure: Not Installed msgpack-python: 0.4.7 mysql-python: Not Installed pycparser: 2.14 pycrypto: 2.6.1 pygit2: Not Installed Python: 2.7.12 (v2.7.12:d33e0cf91556, Jun 2 0 64 bit (AMD64)] python-gnupg: 0.3.8 PyYAML: 3.11 PyZMQ: 15.2.0 RAET: Not Installed smmap: 0.9.0 timelib: 0.2.4 Tornado: 4.3 ZMQ: 4.1.2

System Versions: dist: machine: AMD64 release: 7 system: Windows version: 7 6.1.7601 SP1 Multiprocessor Free

stjack99 commented 8 years ago

I just updated the master to 2016.3.3 and the behavior stays the same.

damon-atkins commented 8 years ago

Did you mean available_version (which does not exist) or something else like pkg.latest_version. Please provide the out put for pkg.list_available and pkg.latest_version showing the command. Best to run salt-call -l info pkg.latest_version app on the windows server itself when trying to workout why something is not working.

stjack99 commented 8 years ago

pkg.available_version

C:\salt>salt-call -l info pkg.available_version app [INFO ] Caching directory 'win/repo-ng/' for environment 'base' ... [INFO ] Fetching file from saltenv 'base', * skipped * latest already in cache 'salt://win/repo-ng/app.sls' ... local: 18.2.28

pkg.list_available

C:\salt>salt-call -l info pkg.list_available app local:

  • 18.2.22
  • 18.2.28

pkg.latest_version

C:\salt>salt-call -l info pkg.latest_version app [INFO ] Caching directory 'win/repo-ng/' for environment 'base' ... [INFO ] Fetching file from saltenv 'base', * skipped * latest already in ca che 'salt://win/repo-ng/app.sls' ... local: 18.2.28

Version 18.2.22 is installed. With .28 enabled in the repo-ng sls file, a 'pkg.remove app' give me this:

C:\salt>salt-call pkg.remove app [INFO ] Executing command 'Powershell -NonInteractive "Import-Module ServerMa nager"' in directory 'C:\Users\bpadmin' [INFO ] Executing command 'Powershell -NonInteractive "$PSVersionTable.PSVers ion.Major | ConvertTo-Json"' in directory 'C:\Users\bpadmin' [ERROR ] Command '$PSVersionTable.PSVersion.Major | ConvertTo-Json' failed wit h return code: 1 [ERROR ] output: The term 'ConvertTo-Json' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:49

  • $PSVersionTable.PSVersion.Major | ConvertTo-Json <<<<
    • CategoryInfo : ObjectNotFound: (ConvertTo-Json:String) [], Comm andNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException [ERROR ] app None not installed local:

      app:

      current: 18.2.28 not installed

That is with .22 installed:

C:\salt>salt-call pkg.list_pkgs local:

... app: 18.2.22 ...

damon-atkins commented 8 years ago

available_version is being deprecated it just calls latest_version salt-call -l info pkg.refresh_db then try salt-call -l debug pkg.refresh_db # don't post this, way to big.

PS Please use the code quote for out put from salt

stjack99 commented 8 years ago

I don't see any issues in the debug output. Here's the relevant section from the debug:

[PROFILE ] Time (in seconds) to render 'c:\salt\var\cache\salt\minion\files\base\win\repo-ng\app.sls' using 'jinja' renderer: 0.0320000648499 [DEBUG ] Rendered data from file: c:\salt\var\cache\salt\minion\files\base\win \repo-ng\app.sls: app: '18.2.22': full_name: 'derpy app' installer: 'http://herp.derp.com/installs/app/18.2.22/appInstaller.exe' uninstaller: 'http://herp.derp.com/installs/app/18.2.22/appInstaller.exe' install_flags: '/s /v"/qn"' uninstall_flags: '/s /x /v"/qn"' msiexec: False locale: en_US reboot: False

'18.2.28': full_name: 'derpy app' installer: 'http://herp.derp.com/installs/app/18.2.28/appInstaller.exe' uninstaller: 'http://herp.derp.com/installs/app/18.2.28/appInstaller.exe' install_flags: '/s /v"/qn"' uninstall_flags: '/s /x /v"/qn"' msiexec: False locale: en_US reboot: False

[DEBUG ] Results of YAML rendering: OrderedDict([('app', OrderedDict([('18.2.22', OrderedDict([('full_name', 'derpy app'), ('installer', 'http://herp.derp.com/installs/app/18.2.22/appInstaller.exe'), ('uninstaller', 'http://herp.derp.com/installs/app/18.2.22/appInstaller.exe'), ('install_flags', '/s /v"/qn"'), ('uninstall_flags', '/s /x /v"/qn"'), ('msiexec', False), ('locale', 'en_US'), ('reboot', False)])), ('18.2.28', OrderedDict([('full_name', 'derpy app'), ('installer', 'http://herp.derp.com/installs/app/18.2.22/appInstaller.exe'), ('uninstaller', 'http://herp.derp.com/installs/app/18.2.22/appInstaller.exe'), ('install_flags', '/s /v"/qn"'), ('uninstall_flags', '/s /x /v"/qn"'), ('msiexec', False), ('locale', 'en_US'), ('reboot', False)]))]))])

morganwillcock commented 8 years ago

Version 18.2.22 is installed. With .28 enabled in the repo-ng sls file, a 'pkg.remove app' give me this: C:\salt>salt-call pkg.remove app

This is already a known problem, which I don't think is fixed yet... #34821

I'm not sure if this is the whole problem, but it looks like something isn't defined properly (unless your app is called None):

[ERROR ] app None not installed

...but all the indents have been stripped when you posted, so it's a bit tricky to see if there is a mistake. If post your state in <pre></pre> tags it should be easier to rule out a mistake. I recently had to downgrade some software in this way, and then upgrade it again a few weeks later, I didn't install with a pkgs list, but other than that the logic was the same as yours.

stjack99 commented 8 years ago

This is definitely related to #34821.

Going to do more testing to see if I can get my state to work.

stjack99 commented 8 years ago

This is my current state:

app-install:
  pkg.installed:
    - name: app
    - version: 18.2.28
    - require:
      - app-remove-18-2-22
app-remove-18-2-22:
  pkg.removed:
    - name: app
    - version: 18.2.22

When I run this state, I still get the issue even though I've specifically said what version to remove:


      ID: app-remove-18-2-22
Function: pkg.removed
    Name: app
  Result: False
 Comment: The following packages failed to remove: app.
 Started: 20:32:16.424000
Duration: 141.0 ms
 Changes:
          ----------
          app:
              ----------
              current:
                  18.2.28 not installed
morganwillcock commented 8 years ago

Did you lose a bit in editing? It lools like the 'require' is missing 'pkg: '

    - require:
      - pkg: app-remove-18-2-22
stjack99 commented 8 years ago

I've tried both. Remove pkg: to see if that was causing the issue.

morganwillcock commented 8 years ago

It was definitely okay previously, here's mine:

remove_app:
  pkg.removed:
    - name: app
    - version: 8.1.18.10669
install_app:
  pkg.installed:
    - name: app
    - version: 8.1.16.10612
    - require:
      - pkg: remove_app

The only thing that looks different to mine, is the order of how the version are defined:

{% for version in (('18.2.22'), ('18.2.28')) %}

...since it's an ordered dict maybe its always needs to be descending (all the examples are descending), I would have written it as:

{% for version in '18.2.28', '18.2.22' %}

Maybe try that with a pkg.refresh_db. You should also check for any old sls files in your cache folder, if you've renamed the folders in repo-ng you can break the name map.

Ch3LL commented 8 years ago

@stjack99 did @morganwillcock 's suggestion help you with a workaround this issue?

stjack99 commented 8 years ago

@Ch3LL No. I'm still having the same issue. At this point, I think we're just going to manage package updates using a multi-step process: create list of minions with package, foreach remove package, enable new package in repo, foreach install package.

Hopefully this gets fixed in the future.

Also, one last thing: doing a pkg.remove from the cli works fine. But doing a module.run for okg.remove in a state shows the same issue as everything else, so it looks like whatever is causing this issue is related to the scope of executing states.

damon-atkins commented 8 years ago

Could you please place win_pkg in the title makes it easier to fine latter.

morganwillcock commented 8 years ago

Just noticed that in your YAML debug results, the version numbers seem a little mixed up:

('18.2.28', OrderedDict([('full_name', 'derpy app'), ('installer', 'http://herp.derp.com/installs/app/18.2.22/appInstaller.exe'), ('uninstaller', 'http://herp.derp.com/installs/app/18.2.22/appInstaller.exe'), ('install_flags', '/s /v"/qn"'), ('uninstall_flags', '/s /x /v"/qn"'), ('msiexec', False), ('locale', 'en_US'), ('reboot', False)]))

Is that just from editing?

Ch3LL commented 8 years ago

bump @stjack99 did you see @morganwillcock 's comments?

stjack99 commented 8 years ago

That was just an editing bug. The YAML appears to be correctly formed.

To clarify the behavior

So, the bug appears to be that salt will only operate on packages using the newest version it knows about. So that if you don't have the current version already installed, you can't perform an uninstall. Additionally, if you have an older version installed and salt tries to install a newer one, Salt does not run the uninstaller for the older version first.

morganwillcock commented 8 years ago

Okay, I can see the same issue when trying to uninstall anything but the newest version. I think this is an extension of the bug that is already open (or least I just didn't realise the full extent of the problem at the time because I've only ever downgraded from the newest version). I've tested on 2016.3.1, 2016.3.2, and 2016.3.3.

Ch3LL commented 8 years ago

Thanks for all the investigation work on this guys. We will need to get this fixed up alongside what was initially reported in issue #34821 so therefore will keep both issues open to be fixed. Thanks!

absolutejam commented 7 years ago

Is this waiting for the new Salt release? Or does it need somebody to look at it?

damon-atkins commented 7 years ago

Windows supports same software installed multiple times. Generally the installer removes the old version before installing the new version, if the software only supports one version installed at a time.

With version 18.2.22 installed and 18.2.28 enabled in the repo pkg.install app - works, but now I have 18.2.22 and 18.2.28 installed. Salt does not try to uninstall 18.2.22 first pkg.remove app version=18.2.22 - fails with error that 18.2.28 is not installed.

Try pkg.list_pkgs versions_as_list=True should list both versions if both are installed.

absolutejam commented 7 years ago

I was experiencing this issue until I realized I was running an older version of the minion 🤦‍♂️ , so I'm out.

damon-atkins commented 6 years ago

@stjack99 Please upgrade your minion. and then try the latest copy of code of win_pkg.py

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.