puppet-prod/site/profiles/manifests/puppet/g10k.pp

89 lines
2.6 KiB
Puppet

# Class: profiles::puppet::g10k
#
# This class handles downloading and installation of the g10k tool, a fast
# Git and Forge based Puppet environment and module deployment tool.
# The latest release of g10k is downloaded from GitHub and placed into '/opt/puppetlabs/bin'.
# Additionally, it creates a helper script to easily run g10k with the appropriate configuration.
# It also creates a systemd service and timer that runs the g10k script every minute.
#
# Parameters: None
#
# Actions:
# - Downloads the latest g10k release from GitHub.
# - Extracts the download and places the executable in '/opt/puppetlabs/bin'.
# - Creates a helper script '/opt/puppetlabs/bin/puppet-g10k' for easy usage of g10k.
# - Creates a systemd service and timer that runs the g10k script every minute.
#
# Usage:
# Directly including the class in your node definitions or classify your nodes
# using an ENC or Hiera.
# Example:
# node 'puppet.example.com' {
# include profiles::puppet::g10k
# }
#
# Requirements:
# - The 'puppet-archive' module should be installed in your puppetmaster.
# - The 'puppet-systemd' module should be installed on your puppetmaster.
# - '/opt/puppetlabs/bin/' directory must exist and be writable.
# - Puppet master must have access to the GitHub URL.
#
# Limitations:
# This is designed to work on Unix-like systems only.
class profiles::puppet::g10k (
String $bin_path,
String $cfg_path,
String $environments_path,
String $default_environment,
){
archive { '/tmp/g10k.zip':
ensure => present,
source => 'https://github.com/xorpaul/g10k/releases/latest/download/g10k-linux-amd64.zip',
extract => true,
extract_path => '/opt/puppetlabs/bin',
creates => '/opt/puppetlabs/bin/g10k',
cleanup => true,
require => Package['unzip']
}
file { '/opt/puppetlabs/bin/puppet-g10k':
ensure => file,
owner => 'root',
group => 'root',
mode => '0755',
content => template('profiles/puppet/g10k/puppet-g10k.erb'),
require => Archive['/tmp/g10k.zip'],
}
$_timer = @(EOT)
[Unit]
Description=puppet-g10k downloader timer
[Timer]
OnCalendar=*:0/1
RandomizedDelaySec=1s
[Install]
WantedBy=timers.target
EOT
$_service = @(EOT)
[Unit]
Description=puppet-g10k downloader service
[Service]
Type=oneshot
ExecStart=/opt/puppetlabs/bin/puppet-g10k
User=root
Group=root
PermissionsStartOnly=false
PrivateTmp=no
EOT
systemd::timer { 'puppet-g10k.timer':
timer_content => $_timer,
service_content => $_service,
active => true,
enable => true,
require => File['/opt/puppetlabs/bin/puppet-g10k'],
}
}