简体   繁体   中英

SaltStack - How to reinstall package when version did not change

We are using salt stack to deploy our app as a debian package. The application itself is Scala and uses Java style versioning, eg during development the version number stays for example at 1.5.0-SNAPSHOT. But the package itself is always updated.

The problem is that salt stack only re-install when there is an update to the version. But for us the version stays the same but the content changes.

So far we are helping ourselves by always removing the package first

my-app-removed:   pkg.removed:
  - name: my-app

my-app:   pkg.installed:
  - sources:
    - my-app: salt://my-app-1-5-0-SNAPSHOT.deb

But this always re-installs, so state.highstate always triggers a change. Is there another way to this, to make dpkg / pkg on debian to also upgrade same version numbers if, and only if, the content changed?

We also checked the verify flag for the pkg state (which basically installs also if any file changed), but that didn't work and the doc also says only yum supports it at the moment.

The onchanges requisite makes a state run only if the dependent state has changes. So, I'd keep a local cache of the .deb file, and detect when it changes, and only remove the pkg if the file changes. (You also do the install from the locally cached file.)

snapshot-deb-file:
  file.managed:
    - name: /var/cache/my-app-1-5-0-SNAPSHOT.deb
    - source: salt://my-app-1-5-0-SNAPSHOT.deb

my-app-removed:
  pkg.removed:
    - name: my-app
    - onchanges:
      - file: snapshot-deb-file

my-app:   
  pkg.installed:
    - sources:
      - my-app: /var/cache/my-app-1-5-0-SNAPSHOT.deb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM