Puppet Class: psick::hosts::dynamic

Defined in:
manifests/hosts/dynamic.pp

Overview

::psick::hosts::dynamic Derived from github.com/example42/puppet-hosts Manage /etc/hosts dynamically. Requires puppetdb

Parameters:

  • dynamic_magicvar (String) (defaults to: '')
  • dynamic_exclude (Boolean) (defaults to: false)
  • dynamic_ip (String) (defaults to: $facts['networking']['ip'])
  • dynamic_alias (Array) (defaults to: [$facts['networking']['hostname']])
  • extra_hosts (Hash) (defaults to: {})
  • manage (Boolean) (defaults to: $psick::manage)
  • noop_manage (Boolean) (defaults to: $psick::noop_manage)
  • noop_value (Boolean) (defaults to: $psick::noop_value)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'manifests/hosts/dynamic.pp', line 5

class psick::hosts::dynamic (
  String $dynamic_magicvar = '', # lint:ignore:params_empty_string_assignment
  Boolean $dynamic_exclude = false,
  String  $dynamic_ip      = $facts['networking']['ip'],
  Array  $dynamic_alias    = [$facts['networking']['hostname']],
  Hash  $extra_hosts       = {},
  Boolean $manage          = $psick::manage,
  Boolean $noop_manage     = $psick::noop_manage,
  Boolean $noop_value      = $psick::noop_value,
) {
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }
    $magic_tag = getvar('dynamic_magicvar')

    $real_tag = $dynamic_exclude ? {
      true    => 'Excluded',
      default => "env-${magic_tag}",
    }

    @@host { $facts['networking']['fqdn']:
      ip           => $dynamic_ip,
      host_aliases => $dynamic_alias,
      tag          => $real_tag,
    }

    Host <<| tag == "env-${magic_tag}" |>> {
      ensure  => present,
    }

    if $extra_hosts != {} {
      $extra_hosts.each | $k,$v | {
        host { $k:
          * => $v,
        }
      }
    }
  }
}