Puppet Class: psick::network

Defined in:
manifests/network.pp

Summary

This psick profile manages network settings, such as interfaces and

Overview

psick::network

routes.

Examples:

Include it to manage network resources

include psick::network

Include in PSICK via hiera (yaml)

psick::profiles::linux_classes:
  network: psick::network

Set no-noop mode and enforce changes even if noop is set for the agent

psick::network::no_noop: true

Parameters:

  • bonding_mode

    Define bonding mode (default: active-backup)

  • network_template

    The erb template to use, only on RedHad derivatives, for the file /etc/sysconfig/network

  • routes

    Hash of routes to pass to ::network::mroute define Note: This is not a real class parameter but a key looked up via lookup(‘psick::network::routes’, {})

  • interfaces

    Hash of interfaces to pass to ::network::interface define Note: This is not a real class parameter but a key looked up via lookup(‘psick::network::interfaces’, {}) Note that this psick automatically adds some default options according to the interface type. You can override them in the provided hash

  • manage (Boolean) (defaults to: $psick::manage)

    If to actually manage any resource in this profile or not

  • auto_prereq (Boolean) (defaults to: $psick::auto_prereq)

    If to automatically install eventual dependencies. Set to false if you have problems with duplicated resources, being sure that you provide the needed prerequistes.

  • options_hash (Hash) (defaults to: {})

    An custom hash of keypair which may be used in templates to manage any network setting.

  • module (String) (defaults to: 'psick')

    What module to use to manage network. By default psick is used. The specified module name, if different, must be added to Puppetfile.

  • no_noop

    Set noop metaparameter to false to all the resources of this class. This overrides any noop setting which might be in place.

  • ensure (Psick::Ensure) (defaults to: 'present')
  • noop_manage (Boolean) (defaults to: $psick::noop_manage)
  • noop_value (Boolean) (defaults to: $psick::noop_value)
  • hostname (Optional[String]) (defaults to: undef)
  • host_conf_template (Optional[String]) (defaults to: undef)
  • host_conf_options (Hash) (defaults to: {})
  • nsswitch_conf_template (Optional[String]) (defaults to: undef)
  • nsswitch_conf_options (Hash) (defaults to: {})
  • use_netplan (Boolean) (defaults to: false)
  • interfaces_merge_behaviour (Enum['first','hash','deep']) (defaults to: 'first')
  • interfaces_defaults (Hash) (defaults to: {})
  • routes_merge_behaviour (Enum['first','hash','deep']) (defaults to: 'first')
  • routes_defaults (Hash) (defaults to: {})
  • rules_merge_behaviour (Enum['first','hash','deep']) (defaults to: 'first')
  • rules_defaults (Hash) (defaults to: {})
  • tables_merge_behaviour (Enum['first','hash','deep']) (defaults to: 'first')
  • tables_defaults (Hash) (defaults to: {})
  • service_restart_exec (String) (defaults to: 'service network restart')
  • config_file_notify (Variant[Resource,String[0,0],Undef,Boolean]) (defaults to: true)
  • config_file_require (Variant[Resource,String[0,0],Undef,Boolean]) (defaults to: undef)
  • config_file_per_interface (Boolean) (defaults to: true)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
# File 'manifests/network.pp', line 38

class psick::network (
  Psick::Ensure   $ensure               = 'present',
  Boolean         $manage               = $psick::manage,
  Boolean         $auto_prereq          = $psick::auto_prereq,
  Hash            $options_hash         = {},
  String          $module               = 'psick',
  Boolean          $noop_manage         = $psick::noop_manage,
  Boolean          $noop_value          = $psick::noop_value,

  Optional[String] $hostname = undef,

  Optional[String]                    $host_conf_template = undef,
  Hash                                $host_conf_options  = {},

  Optional[String]                $nsswitch_conf_template = undef,
  Hash                            $nsswitch_conf_options  = {},

  Boolean $use_netplan                                    = false,
  # This "param" is looked up in code according to interfaces_merge_behaviour
  # Optional[Hash]              $interfaces               = undef,
  Enum['first','hash','deep'] $interfaces_merge_behaviour = 'first',
  Hash                        $interfaces_defaults        = {},

  # This "param" is looked up in code according to routes_merge_behaviour
  # Optional[Hash]              $routes                   = undef,
  Enum['first','hash','deep'] $routes_merge_behaviour     = 'first',
  Hash                        $routes_defaults            = {},

  # This "param" is looked up in code according to rules_merge_behaviour
  # Optional[Hash]              $rules                    = undef,
  Enum['first','hash','deep'] $rules_merge_behaviour      = 'first',
  Hash                        $rules_defaults             = {},

  # This "param" is looked up in code according to tables_merge_behaviour
  # Optional[Hash]              $tables                   = undef,
  Enum['first','hash','deep'] $tables_merge_behaviour     = 'first',
  Hash                        $tables_defaults            = {},

  String $service_restart_exec                            = 'service network restart',
  Variant[Resource,String[0,0],Undef,Boolean] $config_file_notify  = true,
  Variant[Resource,String[0,0],Undef,Boolean] $config_file_require = undef,
  Boolean $config_file_per_interface                     = true,

) {
  # We declare resources only if $manage = true
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }

    $manage_config_file_notify = $config_file_notify ? {
      true    => "Exec[${service_restart_exec}]",
      false   => undef,
      ''      => undef,
      undef   => undef,
      default => $config_file_notify,
    }
    $manage_config_file_require  = $config_file_require ? {
      true    => undef,
      false   => undef,
      ''      => undef,
      undef   => undef,
      default => $config_file_require,
    }

    # Exec to restart interfaces
    exec { $service_restart_exec :
      command     => $service_restart_exec,
      alias       => 'network_restart',
      refreshonly => true,
      path        => $facts['path'],
    }

    if $hostname {
      contain psick::network::hostname
    }

    # Manage /etc/host.conf if $host_conf_template is set
    if $host_conf_template {
      $host_conf_template_type=$host_conf_template[-4,4]
      $host_conf_content = $host_conf_template_type ? {
        '.epp'  => epp($host_conf_template, { options => $host_conf_options }),
        '.erb'  => template($host_conf_template),
        default => template($host_conf_template),
      }
      file { '/etc/host.conf':
        ensure  => file,
        content => $host_conf_content,
        notify  => $manage_config_file_notify,
      }
    }

    # Manage /etc/nsswitch.conf if $nsswitch_conf_template is set
    if $nsswitch_conf_template {
      $nsswitch_conf_template_type=$nsswitch_conf_template[-4,4]
      $nsswitch_conf_content = $nsswitch_conf_template_type ? {
        '.epp'  => epp($nsswitch_conf_template, { options => $nsswitch_conf_options }),
        '.erb'  => template($nsswitch_conf_template),
        default => template($nsswitch_conf_template),
      }
      file { '/etc/nsswitch.conf':
        ensure  => file,
        content => $nsswitch_conf_content,
        notify  => $manage_config_file_notify,
      }
    }

    # Declare network interfaces based on network::interfaces
    $interfaces = lookup('psick::network::interfaces',Hash,$interfaces_merge_behaviour, {})
    $interfaces.each |$k,$v| {
      psick::network::interface { $k:
        * => $interfaces_defaults + $v,
      }
    }

    # Declare network routes based on network::routes
    $routes = lookup('psick::network::routes',Hash,$routes_merge_behaviour, {})
    $routes.each |$k,$v| {
      psick::network::route { $k:
        * => $routes_defaults + $v,
      }
    }

    # Declare network rules based on network::rules
    $rules = lookup('psick::network::rules',Hash,$rules_merge_behaviour, {})
    $rules.each |$k,$v| {
      psick::network::rule { $k:
        * => $rules_defaults + $v,
      }
    }

    # Declare network tables based on network::tables
    $tables = lookup('psick::network::tables',Hash,$tables_merge_behaviour, {})
    $tables.each |$k,$v| {
      psick::network::table { $k:
        * => $tables_defaults + $v,
      }
    }
  }
}