Puppet Class: puppet_agent
- Inherits:
- puppet_agent::params
- Defined in:
- manifests/init.pp
Summary
Upgrades Puppet 4 and newer to the requested version.Overview
example for clients in dmz:s that need to use proxy to reach the repo
provided by puppetserver.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'manifests/init.pp', line 105
class puppet_agent (
String $arch = $facts['os']['architecture'],
String $collection = $puppet_agent::params::collection,
Boolean $is_pe = $puppet_agent::params::_is_pe,
Boolean $manage_pki_dir = true,
Boolean $manage_repo = true,
String $package_name = 'puppet-agent',
Optional $package_version = undef,
Array $service_names = $puppet_agent::params::service_names,
Optional $source = undef,
Optional $absolute_source = undef,
String $yum_source = 'http://yum.puppet.com',
String $apt_source = 'https://apt.puppet.com',
String $mac_source = 'https://downloads.puppet.com',
String $windows_source = 'https://downloads.puppet.com',
String $solaris_source = 'puppet:///pe_packages',
String $aix_source = 'puppet:///pe_packages',
Boolean $use_alternate_sources = false,
Optional $alternate_pe_source = undef,
Optional[Stdlib::Absolutepath] $install_dir = undef,
Boolean $disable_proxy = false,
Optional $proxy = undef,
Array $install_options = [],
String $skip_if_unavailable = 'absent',
Boolean $msi_move_locked_files = false,
Optional $wait_for_pxp_agent_exit = undef,
Optional $wait_for_puppet_run = undef,
Array[Puppet_agent::Config] $config = [],
String $version_file_path = $facts['os']['family'] ? { 'windows' => "${facts['env_windows_installdir']}\\VERSION", default => '/opt/puppetlabs/puppet/VERSION' }
) inherits puppet_agent::params {
# The configure class uses $puppet_agent::config to manage settings in
# puppet.conf, and will always be present. It does not require management of
# the agent package. Dependencies for configure will be declared later if the
# puppet_agent::prepare and puppet_agent::install are also added to the
# catalog.
contain('puppet_agent::configure')
if (getvar('::aio_agent_version') == undef) {
fail('The puppet_agent module does not support pre-Puppet 4 upgrades.')
}
if $package_version == 'latest' and $facts['os']['family'] =~ /^(?i:windows|solaris|aix|darwin)$/ {
fail("Setting package_version to 'latest' is not supported on ${$facts['os']['family'].capitalize()}")
}
if $source != undef and $absolute_source != undef {
fail('Only one of $source and $absolute_source can be set')
}
if $package_version == undef {
info('puppet_agent performs no actions if a package_version is not specified')
} elsif defined('$::pe_server_version') {
info('puppet_agent performs no actions on PE infrastructure nodes to prevent a mismatch between agent and PE components')
} else {
# In this code-path, $package_version != undef AND we are not on a PE infrastructure
# node since $::pe_server_version is not defined
if $facts['os']['architecture'] == 'x86' and $arch == 'x64' {
fail('Unable to install x64 on a x86 system')
}
# The AIO package version and Puppet version can, on rare occasion, diverge.
# This logic checks for the AIO version of the server, since that's what the package manager cares about.
if $package_version == 'auto' {
$master_or_package_version = chomp(file($version_file_path))
} else {
$master_or_package_version = $package_version
}
if $facts['os']['family'] == 'redhat' {
if $master_or_package_version !~ /^\d+\.\d+\.\d+.*$|^latest$|^present$/ {
fail("invalid version ${master_or_package_version} requested")
}
} else {
if $master_or_package_version !~ /^\d+\.\d+\.\d+([.-]?\d*|\.\d+\.g[0-9a-f]+)$|^latest$|^present$/ {
fail("invalid version ${master_or_package_version} requested")
}
}
# Strip git sha from dev builds
if $master_or_package_version =~ /.g/ {
$_expected_package_version = split($master_or_package_version, /[.-]g.*/)[0]
} elsif $facts['os']['family'] == 'redhat' {
$_expected_package_version = $master_or_package_version.match(/^\d+\.\d+\.\d+|^latest$|^present$/)[0]
} else {
$_expected_package_version = $master_or_package_version
}
if $_expected_package_version == 'latest' {
$aio_upgrade_required = true
$aio_downgrade_required = false
} elsif $_expected_package_version == 'present' {
$aio_upgrade_required = false
$aio_downgrade_required = false
} else {
$aio_upgrade_required = versioncmp($facts['aio_agent_version'], $_expected_package_version) < 0
$aio_downgrade_required = versioncmp($facts['aio_agent_version'], $_expected_package_version) > 0
}
if $aio_upgrade_required {
if any_resources_of_type('filebucket', { path => false }) {
if $settings::digest_algorithm != $facts['puppet_digest_algorithm'] {
fail("Remote filebuckets are enabled, but there was a agent/server digest algorithm mismatch. Server: ${settings::digest_algorithm}, agent: ${facts['puppet_digest_algorithm']}. Either ensure the algorithms are matching, or disable remote filebuckets during the upgrade.")
}
}
}
if $facts['os']['name'] == 'Solaris' and $facts['os']['release']['major'] == '11' {
# Strip letters from development builds. Unique to Solaris 11 packaging.
$_version_without_letters = regsubst($master_or_package_version, '[a-zA-Z]', '', 'G')
$_version_without_orphan_dashes = regsubst($_version_without_letters, '(^-|-$)', '', 'G')
$_package_version = regsubst($_version_without_orphan_dashes, '\b(?:0*?)([1-9]\d*|0)\b', '\1', 'G')
} else {
$_package_version = $master_or_package_version
}
class { 'puppet_agent::prepare':
package_version => $_package_version,
}
class { 'puppet_agent::install':
package_version => $_package_version,
install_dir => $install_dir,
install_options => $install_options,
}
contain('puppet_agent::prepare')
-> contain('puppet_agent::install')
-> Class['puppet_agent::configure']
# Service management:
# - Under Puppet Enterprise, the agent nodegroup is managed by PE, and we don't need to manage services here.
# - On Windows, services are handled by the puppet-agent MSI packages themselves.
# ...but outside of PE, on other platforms, we must make sure the services are restarted. We do that with the
# ::puppet_agent::service class. Make sure it's applied after the install process finishes if needed:
if $facts['os']['family'] != 'windows' and (!$is_pe or versioncmp($facts['clientversion'], '4.0.0') < 0) {
Class['puppet_agent::configure']
~> contain('puppet_agent::service')
}
}
}
|