Using Salt Stack to upgrade an already install RPM.

Salt - Reinstall Package from RPMΒΆ

I hit a small issue trying to install a new version of Node.js on our web servers this week. We had previously installed Node v0.6 from a repo that is now defunct. We wanted to upgrade our web cluster to v0.8 through salt, but ran into problems trying to purge the old package. So, here is a shortcut for reinstalling a new package from RPM:

# Node

{% set node_ver = '0.8.18-1' %}

    - sources:
      - nodejs: salt://node/nodejs-{{ node_ver }}.{{ grains['cpuarch'] }}.rpm
    - watch:
      - module: nodejs-old

    - name: /bin/true
    - onlyif: "rpm -q nodejs && ! rpm -q nodejs-{{ node_ver }}"
    - name: pkg.purge
    - pkgs: nodejs
    - watch:
      - cmd: nodejs-old

In this example, is only run if nodejs is installed and not the version we are trying to install. If is triggered, it runs /bin/true, which causes the module.wait watch to trigger, thus purging the package from the system. The install check is performed last, which installs Node.