0

I'm working on salt-stack for setting up multiple machines, I wanted to ask how can we deploy rpms(placed at a custom location in master) on to the minions? I already have an idea of how can we install packages using top.sls file and name of the package that needs to be installed on minions but what I'm looking for is to deploy my custom rpms on to the minions from master.

  • It is generally a good practice to [show the code](https://stackoverflow.com/help/minimal-reproducible-example) that you tried (in question). For starters, have a look at [pkg state](https://docs.saltproject.io/en/3002/ref/states/all/salt.states.pkg.html#salt.states.pkg.installed), specifically the `pkg.installed` function. – seshadri_c Jul 26 '21 at 14:24
  • Actually, what I want to understand is, if multiple rpms is placed inside master at some location how can we install those rpms to minions using pkg.installed. I have read a reference from https://stackoverflow.com/questions/44593704/successfully-install-artifactory-rpm-using-salt-stack but it isn't working. – numan sheikh Jul 29 '21 at 08:32
  • 1
    For your purpose, you should be using the `sources:` option of `pkg.installed` module. And what do you mean by *isn't working*? Any errors, output, etc updated in the question would be appreciated. – seshadri_c Jul 29 '21 at 17:53
  • Thanks for the reply @seshadri_c In my case all RPMS that are to be installed are placed in a directory, and in the sources: option we need to provide the exact name of the file in case If in future my RPMs name is changed, e.g. from my-rpm-5.7.1-1 to my-rpm-5.7.2-2 I would have to make changes again in the script instead I want to provide a regex in sources like my-rpm*.rpm, is it possible in any way to do this, thanks – numan sheikh Jul 30 '21 at 05:26

1 Answers1

1

There are two ways to approach this:

Option 1:

Define the list of RPMs in a pillar file:

package_names:
  - custom-rpm1: custom-rpm1-2.6.1-2.el7.x86_64.rpm
  - custom-rpm2: custom-rpm2-release-el7-3.noarch.rpm
  - custom-rpm3: custom-rpm3-latest.noarch.rpm

Then in an SLS file:

install-rpm:
  pkg.installed:
  - sources: {{ pillar['package_names'] }}

Option 2:

Copy the directory containing the RPMs (salt://rpms in below example is relative to file_roots) to target machine and use rpm command to install (with wildcard):

copy-rpms-dir:
  file.recurse:
    - name: /tmp/rpms
    - source: salt://rpms

install-rpms:
  cmd.run:
    - name: rpm -ivh /tmp/rpms/*.rpm
    - success_retcodes:
      - 2

Installing with rpm command requires extra check for return codes as it returns non-zero (2) when RPM is already installed.

seshadri_c
  • 6,906
  • 2
  • 10
  • 24
  • Your answer is appreciated but didn't we still are providing the exact names in the pillar file, so every time a new version of RPM comes we might have to change the pillar, right? Can't we provide a regex here so we don't need to edit the file again? – numan sheikh Jul 30 '21 at 11:51
  • Have you seen **Option 2**? If you *really want to go with wildcards*, this might be better. – seshadri_c Jul 30 '21 at 11:58
  • Yes, i already have tried option2 it works well it fails if some minions are not online. The reason why i want to go with approach1 to use Salt configuration management (sls state file). – numan sheikh Jul 30 '21 at 12:10
  • If you want to use Salt configuration management functionality, you should know [pillar](https://docs.saltproject.io/en/getstarted/config/pillar.html), and that pillar values can be passed without editing files. – seshadri_c Jul 31 '21 at 01:59