Defined Type: tp::conf
- Defined in:
- manifests/conf.pp
Overview
This define manages configuration files for the application named in the used title.. It can manage the content of the managed files using different methods (source, template, epp, content) The actual path of the managed configuration files is determined by various elements:
-
If the path parameter is explicitly set, that’s always the path used
tp::conf { ‘openssh::root_config’:
path => '/root/.ssh/config', # This is the path of the managed file content => template('site/openssh/root_config.erb'),
}
-
If path parameter is not set and the title contains only the app name, which is the basic and most direct usage, then it’s managed the *main configuration file* of the application, as defined by the variable config_file_path in the tp/data/$app directory according to the underlying OS.
tp::conf { ‘openssh’: # Path is defined by tp $settings
template => 'site/openssh/sshd_config.erb',
}
-
When the base_file parameter is specified the path of the managed file is # looked in the value of the key $base_file_file_path in the tp/data/$app directory tp::conf { ‘openssh’: # Path is defined by tp $settings
template => 'site/openssh/init.erb', base_file => 'init',
}
-
When the title has a format like: app::file and no base_dir is set the path is composed using the app’s *main configuration directory* and the file name used in the second part of the title (after the ::)
tp::conf { ‘openssh::ssh_config’: # Path is $settings/ssh_config
template => 'site/openssh/ssh_config.erb',
}
-
When the title has a format like: app::file it’s also possible to specify, with the base_dir parameter, the directory where to place the file:
tp::conf { ‘apache::example42.com.conf’:
template => 'site/apache/example42.com.conf.erb', base_dir => 'conf',
} Path is: $settings/example42.com.conf
See below for more examples.
(/etc/ssh/sshd_config) using a template
tp::conf { 'openssh':
template => 'site/openssh/sshd_config',
options_hash => lookup('openssh::options_hash'),
}
a static source
tp::conf { 'openssh::ssh_config':
source => 'puppet:///modules/site/openssh/ssh_config',
}
in directory called conf.d or *.d ). Note that here is used as $base_dir ‘conf’ instead of the default ‘config’. For example with Apache on RedHat: ‘config’ dir is ‘/etc/httpd’ ‘conf’ dir is ‘/etc/httpd/conf.d’ Other “common” base_dir values are ‘log’, ‘data’ but actually any value can be used as long as there’s a corresponding key in the TP settings data.
tp::conf { 'rsyslog::logserver':
content => "*.* @@syslog.example42.com\n",
base_dir => 'conf',
}
explicit path given and the content populated via a Puppet epp template. In this case the title is not used for any specific purpose, but it should have a unique name and refer to the relevat app in the first part of the title (before ::)
tp::conf { 'openssh::root_config': # Title must be unique
path => '/root/.ssh/config',
epp => 'site/openssh/root/config.epp',
mode => '0640',
}
changes
tp::conf { 'nginx':
config_file_notify => false,
}
By default, if relevant tinydata is present, config files are checked. Use this to disable unwanted validation commands
tp::conf { 'apache::my_vhost.conf':
validate_syntax => false,
base_dir => 'vhost,
source => puppet:///modules/profile/apache/my_vhost.conf',
}
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'manifests/conf.pp', line 216
define tp::conf (
String[1] $ensure = present,
Tp::Fail $on_missing_data = pick(getvar('tp::on_missing_data'),'notify'),
Hash $my_settings = {},
Hash $my_options = {},
Boolean $use_v4 = pick(getvar('tp::use_v4'),false),
Variant[Undef,String,Array] $source = undef,
Variant[Undef,String,Array] $template = undef,
Variant[Undef,String] $epp = undef,
Variant[Undef,String] $content = undef,
String[1] $base_dir = 'config',
String[1] $base_file = 'config',
Enum['global','user'] $scope = 'global',
Variant[Undef,String] $path = undef,
Variant[Undef,String] $mode = undef,
Variant[Undef,String] $owner = undef,
Variant[Undef,String] $group = undef,
String $path_prefix = '', # lint:ignore:params_empty_string_assignment
Boolean $path_parent_create = false,
Variant[Boolean,String] $config_file_notify = true,
Variant[Boolean,String] $config_file_require = true,
Variant[Undef,Boolean] $validate_syntax = undef,
Hash $options_hash = {},
Hash $settings_hash = {},
Boolean $debug = false,
String[1] $debug_dir = '/tmp',
String[1] $data_module = 'tinydata',
) {
# Deprecations
if $settings_hash != {} {
deprecation('settings_hash', 'Replace with my_settings')
}
if $options_hash != {} {
deprecation('options_hash', 'Replace with my_options')
}
if $use_v4 {
# Settings evaluation
$title_elements = split ($title, '::')
$app = $title_elements[0]
$file = $title_elements[1]
# Check if repo or upstream_repo are set in tp::install
if defined_with_params(Tp::Install[$app]) {
$repo = getparam(Tp::Install[$app],'repo')
}
if defined_with_params(Tp::Install[$app]) {
$upstream_repo = getparam(Tp::Install[$app],'upstream_repo')
}
$tp_settings = tp_lookup($app,'settings',$data_module,'deep_merge')
$temp_settings = deep_merge($tp_settings,$settings_hash,$my_settings)
# Find file path
$prefix = $scope ? {
'global' => $facts['identity']['privileged'] ? {
true => '',
false => 'user_',
},
'user' => 'user_',
}
if $file and $file != '' {
$real_dir = pick(getvar("temp_settings.${base_dir}_dir_path"), getvar("temp_settings.${prefix}dirs.${base_dir}.path"))
$auto_path = $base_file ? {
'config' => "${real_dir}/${file}",
default => pick(getvar("temp_settings.${base_file}_file_path"), getvar("temp_settings.${prefix}files.${base_file}.path"))
}
} else {
$auto_path = pick(getvar("temp_settings.${base_file}_file_path"), getvar("temp_settings.${prefix}files.${base_file}.path"))
}
$calculated_path = pick($path, $auto_path)
$real_path = "${path_prefix}${calculated_path}"
$local_file_params = delete_undef_values({
'path' => $real_path,
'mode' => $mode,
'owner' => $owner,
'group' => $group,
})
$local_settings = delete_undef_values({
"${prefix}files" => {
"${base_file}" => $local_file_params,
},
"${base_file}_file_mode" => $mode,
"${base_file}_file_owner" => $owner,
"${base_file}_file_group" => $group,
"${base_file}_file_path" => $real_path,
})
$settings = deep_merge($tp_settings,$settings_hash,$my_settings,$local_settings)
$real_mode = pick(getvar("settings.${base_file}_file_mode"), getvar("settings.${prefix}files.${base_file}.mode"), getvar('settings.config_file_mode')) # lint:ignore:140chars
$real_owner = pick(getvar("settings.${base_file}_file_owner"), getvar("settings.${prefix}files.${base_file}.owner"), getvar('settings.config_file_owner')) # lint:ignore:140chars
$real_group = pick(getvar("settings.${base_file}_file_group"), getvar("settings.${prefix}files.${base_file}.group"), getvar('settings.config_file_group')) # lint:ignore:140chars
# Set options and file content
$tp_options = tp_lookup($app,"options::${base_file}",$data_module,'deep_merge')
$options = deep_merge($tp_options,$options_hash,$my_options,)
$epp_params = {
options => $options,
options_hash => $options_hash,
settings => $settings,
}
if $content {
$content_params = $content
} elsif $template {
$template_ext = $template[-4,4]
$content_params = $template_ext ? {
'.epp' => epp($template,$epp_params),
'.erb' => template($template),
default => template($template),
}
} elsif $epp {
$content_params = epp($epp,$epp_params)
} else {
$content_params = undef
}
# If user doesn't provide a $content, $template or $epp but provides $options_hash we check
# if on tinydata is set config_file_format
$real_config_file_format = pick_default(getvar("settings.${base_file}_file_format"), getvar("settings.${prefix}files.${base_file}.file_format"), getvar("settings.files.${base_file}.file_format"),undef)
if $content_params =~ Undef and $real_config_file_format and $options != {} {
$real_content = $real_config_file_format ? {
'yaml' => to_yaml($options),
'json' => to_json($options),
'hcl' => to_hcl($options),
'inifile' => template('tp/inifile.erb'),
'inifile_with_stanzas' => template('tp/inifile_with_stanzas.erb'),
'spaced' => template('tp/spaced.erb'),
'spaced_with_stanzas' => template('tp/inifile_with_stanzas.erb'),
default => undef,
}
} else {
$real_content = $content_params
}
# Set require if package_name is present
$real_package_name = pick_default(getvar('settings.package_name'), tp::title_replace(getvar('settings.packages.main.name'),$app),undef)
if $real_package_name and $real_package_name != '' {
$package_ref = "Package[${real_package_name}]"
} else {
$package_ref = undef
}
$real_require = $config_file_require ? {
'' => undef,
false => undef,
true => $package_ref,
default => $config_file_require,
}
# Set notify if service_name is present
$real_service_name = pick_default(getvar('settings.service_name'), tp::title_replace(getvar('settings.services.main.name'),$app),undef)
if $real_service_name and $real_service_name != '' {
$service_ref = "Service[${real_service_name}]"
} else {
$service_ref = undef
}
$real_notify = $config_file_notify ? {
'' => undef,
false => undef,
true => $service_ref,
default => $config_file_notify,
}
$validate_cmd = pick_default(getvar('settings.validate_cmd'), getvar("settings.${prefix}files.${base_file}.validate_cmd"), undef) # lint:ignore:140chars
$default_validate_cmd = $validate_cmd ? {
'' => undef,
String => $validate_cmd,
Hash => pick_default(getvar("settings.validate_cmd.${base_dir}"), undef),
Undef => undef,
}
$real_validate_cmd = $validate_syntax ? {
undef => $default_validate_cmd,
true => $default_validate_cmd,
false => undef,
}
# Resources
if $path_parent_create {
$path_parent = dirname($real_path)
exec { "mkdir for tp::conf ${title}":
command => "/bin/mkdir -p ${path_parent}",
creates => $path_parent,
before => File[$real_path],
}
}
$file_params = {
ensure => tp::ensure2file($ensure),
source => $source,
content => $real_content,
path => $real_path,
mode => $real_mode,
owner => $real_owner,
group => $real_group,
require => $real_require,
notify => $real_notify,
validate_cmd => $real_validate_cmd,
}
file { $real_path:
* => $file_params + pick(getvar("settings.${base_file}_file_params"), getvar("settings.${prefix}files.${base_file}.params"), getvar("settings.files.${base_file}.params"), {}),
}
} else {
#v3 code
# Settings evaluation
$title_elements = split ($title, '::')
$app = $title_elements[0]
$file = $title_elements[1]
if defined_with_params(Tp::Install[$app]) {
$repo = getparam(Tp::Install[$app],'repo')
}
if defined_with_params(Tp::Install[$app]) {
$upstream_repo = getparam(Tp::Install[$app],'upstream_repo')
}
$tp_settings = tp_lookup($app,'settings',$data_module,'merge')
$settings = $tp_settings + $settings_hash
$tp_options = tp_lookup($app,"options::${base_file}",$data_module,'merge')
$options = $tp_options + $options_hash
if $file and $file != '' {
$prefix = $scope ? {
'global' => '',
'user' => 'user_',
}
$real_dir = $settings["${prefix}${base_dir}_dir_path"]
$auto_path = $base_file ? {
'config' => "${real_dir}/${file}",
default => $settings["${prefix}${base_file}_file_path"],
}
} else {
$auto_path = $settings["${base_file}_file_path"]
}
$real_path = pick($path, $auto_path)
$manage_path = "${path_prefix}${real_path}"
$manage_mode = pick($mode, $settings[config_file_mode])
$manage_owner = pick($owner, $settings[config_file_owner])
$manage_group = pick($group, $settings[config_file_group])
$epp_params = {
options => $options,
options_hash => $options_hash,
settings => $settings,
}
# Find out the file's content value
if $content {
$content_params = $content
} elsif $template {
$template_ext = $template[-4,4]
$content_params = $template_ext ? {
'.epp' => epp($template,$epp_params),
'.erb' => template($template),
default => template($template),
}
} elsif $epp {
$content_params = epp($epp,$epp_params)
} else {
$content_params = undef
}
# If user doesn't provide a $content, $template or $epp but provides $options_hash we check
# if on tinydata is set config_file_format
if $content_params =~ Undef and $settings[config_file_format] and $options_hash != {} {
$manage_content = $settings[config_file_format] ? {
'yaml' => to_yaml($options_hash),
'json' => to_json($options_hash),
'hcl' => to_hcl($options_hash),
'inifile' => template('tp/inifile.erb'),
'inifile_with_stanzas' => template('tp/inifile_with_stanzas.erb'),
'spaced' => template('tp/spaced.erb'),
'spaced_with_stanzas' => template('tp/inifile_with_stanzas.erb'),
default => undef,
}
} else {
$manage_content = $content_params
}
# Set require if package_name is present
if $settings[package_name] and $settings[package_name] != '' {
$package_ref = "Package[${settings[package_name]}]"
} else {
$package_ref = undef
}
$manage_require = $config_file_require ? {
'' => undef,
false => undef,
true => $package_ref,
default => $config_file_require,
}
# Set notify if service_name is present
if $settings[service_name] and $settings[service_name] != '' {
$service_ref = "Service[${settings[service_name]}]"
} else {
$service_ref = undef
}
$manage_notify = $config_file_notify ? {
'' => undef,
false => undef,
true => $service_ref,
default => $config_file_notify,
}
$default_validate_cmd = $settings['validate_cmd'] ? {
String => $settings['validate_cmd'],
Hash => $settings['validate_cmd'][$base_dir],
Undef => undef,
}
$manage_validate_cmd = $validate_syntax ? {
undef => $default_validate_cmd,
true => $default_validate_cmd,
false => undef,
}
# Resources
if $path_parent_create {
$path_parent = dirname($manage_path)
exec { "mkdir for tp::conf ${title}":
command => "/bin/mkdir -p ${path_parent}",
creates => $path_parent,
before => File[$manage_path],
}
}
$file_params = {
ensure => $ensure,
source => $source,
content => $manage_content,
path => $manage_path,
mode => $manage_mode,
owner => $manage_owner,
group => $manage_group,
require => $manage_require,
notify => $manage_notify,
validate_cmd => $manage_validate_cmd,
}
file { $manage_path:
* => $file_params + pick($settings[config_file_params], {}),
}
# Debugging
if $debug == true {
$debug_scope = inline_template('<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime.*|path|timestamp|free|.*password.*)/ } %>')
file { "tp_conf_debug_${title}":
ensure => $ensure,
content => $debug_scope,
path => "${debug_dir}/tp_conf_debug_${title}",
}
}
}
}
|