## puppet_cd::r10k::install.pp
# Module name: puppet_cd
# Author: Arne Teuke (arne_teuke@confdroid)
# @summary  Class manages r10k installation for the puppet_cd module.
###############################################################################
class puppet_cd::r10k::install (

) inherits puppet_cd::params {
  if ($pt_pm_fqdn == $fqdn) and ($pt_use_r10k == true) {
    # enable CRB
    exec { 'enable_crb':
      command => 'dnf config-manager --set-enabled crb',
      unless  => 'dnf repolist --disabled | grep -qE "crb|CodeReady"',
      path    => ['/usr/bin', '/bin'],
    }

    # install required packages
    package { $pt_r10k_pkg:
      ensure  => $pt_pkg_ensure,
      before  => Package['r10k'],
      require => Exec['enable_crb'],
    }

    # install r10k via gem
    package { 'r10k':
      ensure   => $pt_pkg_ensure,
      provider => gem,
    }

    # create r10k dir
    file { 'r10k_dir':
      ensure   => directory,
      path     => $pt_r10k_dir,
      owner    => 'root',
      group    => 'root',
      mode     => '0755',
      selrange => s0,
      selrole  => object_r,
      seltype  => puppet_etc_t,
      seluser  => unconfined_u,
    }

    # configure r10k.yaml
    file { $pt_r10k_file:
      ensure   => file,
      owner    => 'root',
      group    => 'root',
      mode     => '0644',
      selrange => s0,
      selrole  => object_r,
      seltype  => puppet_etc_t,
      seluser  => unconfined_u,
      require  => File['r10k_dir'],
      content  => template($pt_r10k_erb),
    }
  }
}
