I give you an example. This is what I am doing to ...
# forge-modules
m
I give you an example. This is what I am doing to install the forwarder on different OSs, and it seams a bit too much (we still have 2 systems running CentOS 6 🙈 ):
Copy code
$os_major = $facts['os']['release']['major']
  $repo_base = '<http://repositories.geant.org>'
  $splunk_version = lookup('splunk_universalforwarder_version', String, 'first', '8.0.1')
  $splunk_build = lookup('splunk_universalforwarder_build', String, 'first', '6db836e2fb9e')
  if $facts['os']['family'] == 'RedHat' {
    if $facts['os']['distro']['release']['major'] == '6' {
      $package_suffix = '-linux-2.6-x86_64.rpm'
      $splunk_user = 'splunk'
    } else {
      $package_suffix = '.x86_64.rpm'
      $splunk_user = 'splunkfwd'
    }
    $package_name = "splunkforwarder-${splunk_version}-${splunk_build}${package_suffix}"
    $source_url = "${repo_base}/yum/centos-${os_major}/geant_yum/${package_name}"
    $package_version = "${splunk_version}-${splunk_build}"
    $pin_version = $package_version
    $manage_package_source = false
  } elsif $facts['os']['family'] == 'Debian' {
    $splunk_user = 'splunkfwd'
    $package_name = "splunkforwarder-${splunk_version}-${splunk_build}-linux-2.6-amd64.deb"
    $source_url = "${repo_base}/deb/ubuntu-${os_major}/geant_deb/pool/main/s/splunkforwarder/${package_name}"
    $package_version = 'latest'
    $pin_version = $splunk_version
    $manage_package_source = true
  }
I was expecting a parameter to use my own repository and end of story.
s
Couldn't you replace most of that logic with a few hiera lookups? You already have a lookup for
splunk_universalforwarder_version
and
splunk_universalforwarder_build
. Could you not have a
splunk_universalforwarder_user
that get set to 'splunkfwd' in common.yaml and to 'splunk' in data/OS/RedHat/6.yaml? It seems like almost everything else could also be built up from hiera lookups, rather than programmatic logic.
m
yes, I can make it slightly simpler from my side, but tbh, I rather like an option like as
use_custom_repo
, and then I only need to push the deb and rpm file to my repository. Otherwise the module starts fetching from Splunk using the puppet archive, extracts the file, copy a file onto a staging directory, install it from there ... it's convoluted, with no or little gain. And I'm not mentioning all the variables that have been implemented to build the repository string.... What I would like to achieve is: 1. use a custom Yum, Apt repository 2. use puppet package resource, instead of doing
dpkg -i ...
... 3. eventually, on top of that I could use my own
pin_package
module:
<https://forge.puppet.com/modules/maxadamo/pin_package/readme>