Search code examples
jenkinsartifactorysalt-project

Successfully Install Artifactory RPM using Salt-Stack


I am working on fully automating some things using Salt Stack. I am currently working on installing Artifactory v5.3.2 using a RPM via Salt Stack. I am able to get this to install and work properly but begin getting a false-positive error from salt stack.

Currently running on CentOS Linux release 7.3.1611 (Core) with a masterless salt stack (just for testing purposes) from here. According to Artifactory documentation; they recommend using yum to install the rpm package. Installing Artifactory OSS from an RPM disribution.

I am aware of two salt-formula's for a similar use case but, these are over complicated for our needs. I attempted to post the two urls for them but don't have enough reputation for saltstack to allow me to do so.

After Downloading the rpm and placing it in the correct directory.. using this salt stack configuration does NOT work properly on the first attempt of an install:

jfrog-artifactory-oss.noarch:
  pkg.installed:
    - source: salt://path/conf/jfrog-artifactory-oss-5.3.2.rpm

returning an error message like so:

ID: jfrog-artifactory-oss.noarch
Function: pkg.installed
  Result: False
 Comment: Error occurred installing package(s). Additional info follows:`

         errors:
              - Running scope as unit run-2994.scope.
                Loaded plugins: fastestmirror
                Loading mirror speeds from cached hostfile
                 * base: mirror.steadfast.net
                 * epel: mirror.steadfast.net
                 * extras: repo.us.bigstepcloud.com
                 * updates: mirrors.lga7.us.voxel.net
                No package jfrog-artifactory-oss available.
                Error: Nothing to do
 Started: 15:51:12.374898
Duration: 11271.36 ms
 Changes:

Using this configuration for salt:

jfrog-artifactory-oss.noarch:
  cmd.run:
    - name: yum install -y /srv/salt/prod/path/conf/jfrog-artifactory-oss-5.3.2.rpm

Works the first time but, the second time running it using this format returns an error like so:

          stderr:
              Error: Nothing to do
          stdout:
              Loaded plugins: fastestmirror
              Examining /srv/salt/prod/path/conf/jfrog-artifactory-oss-5.3.2.rpm: jfrog-artifactory-oss-5.3.2-50047.noarch
              /srv/salt/prod/path/conf/jfrog-artifactory-oss-5.3.2.rpm: does not update installed package.

Now, not to make things confusing.. if I have artifactory installed, and I then revert back to the first method of installing this using the pkg.installed method, things work as expected returning a success message saying 'All specified packages are already installed'.

Typically this false positive is caused by not using the correct name of the package in the salt state file so running yum list installed returns jfrog-artifactory-oss.noarch ensuring I am using the correct naming in the salt state.

I am looking to have this work successfully regardless of if it is updating the package or not; without needing to over complicate our set up with the salt formulas provided.

Any help/advice would be greatly appreciated.


Solution

  • Artifactory RPMs could be installed both using yum repository and rpm directly. Personally I would suggest using yum way as it makes future updates easier.

    To answer your concern regarding using masterless setup - both options are fully functional in masterless as well as master-minion setups.

    And one side-note. By default pkg.installed will try to use package manager native to your OS (yum/rpm in case of RedHat/CentOS). In most cases when installing package you should use it instead of calling yum or rpm directly.

    Using yum

    First thing we should do is to get .repo file holing information about yum repositories. Unfortunately, the one referred to in the documentation points to the repository with pro version of Artifactory. As we are interested in OSS - we should use a different one

    To set it up we will first cook the .repo file with the following content:

    [bintray--jfrog-artifactory-rpms]
    name=bintray--jfrog-artifactory-rpms
    baseurl=http://jfrog.bintray.com/artifactory-rpms
    gpgcheck=0
    repo_gpgcheck=0
    enabled=1
    

    Now we should use salt to configure yum to use this .repo file and install Artifactory from this repository. Assuming that yum config file is located in salt tree under files/jfrog-artifactory.repo, Salt configuration will look as follows:

    /etc/yum.repos.d/artifactory.repo:
      file.managed:
        - source: salt://files/jfrog-artifactory.repo
    
    jfrog-artifactory-oss:
      pkg.installed:
         - require:
           - file: /etc/yum.repos.d/artifactory.repo
         - fromrepo: bintray--jfrog-artifactory-rpms
    

    The -fromrepo option will make sure that the package is being installed using specific yum repository just in case it might be available in others.

    Using RPM

    It is also possible to download Artifactory RPM directly to your Salt configuration and install it from there. To do this I've used the following RPM file: https://bintray.com/jfrog/artifactory-rpms/download_file?file_path=jfrog-artifactory-oss-5.3.2.rpm . Assuming the file is downloaded into files/jfrog-artifactory-oss-5.3.2.rpm of your Salt tree, the state installing this package will look as follows:

    jfrog-package:
      pkg.installed:
        - sources:
          - jfrog-artifactory-oss: salt://files/jfrog-artifactory-oss-5.3.2.rpm
    

    Please note, that -sources part is a list of key-value pairs, where key is the name of the package and value is the path to the RPM file. Top-level jfrog-package is just a label