Search code examples
salt-project

Saltstack copy files with specific extension


I need to install specific rpm file which I'm pulling from git and it looks like this "zabbix-agent2-5.2.4-1.el7.x86_64.rpm"

This is state file which I'm using:

install_pkg:
  pkg.installed:
    - sources:
      - zabbix_agen2: salt://some/path/zabbix-agent2-5.2.4-1.el7.x86_64.rpm

The question is, is there any option to specify dynamic file name?

Something like salt://some/path/zabbix-agent2*.rpm

Because in this moment I have to rename file in source directory for something like zabbix-agent2.rpm but I'd like to have that version in it's name.


Solution

  • The sources parameter takes an absolute filename, and doesn't consider wildcards. This is where pillar can be used to dynamically supply the version (at runtime).

    For example:

    install_pkg:
      pkg.installed:
        - sources:
          - zabbix_agen2: salt://some/path/zabbix-agent{{ pillar['zabbix_version'] }}.el7.x86_64.rpm
    

    Pillar values can be supplied from an SLS file in the pillar, or it can be passed when running the state file, like:

    salt myminion state.apply mypkg pillar='{"zabbix_version": "2-5.2.4-1"}'
    

    Here we run the mypkg state on myminion by supplying the version of the package that we would like to install.