Puppet Class: facter_conf

Defined in:
manifests/init.pp

Summary

A class for configuring facter.conf

Overview

Configures facter.conf based on settings available at www.puppet.com/docs/puppet/latest/configuring_facter.html

Examples:

include facter_conf

Parameters:

  • facter_conf_ensure (Enum['present','absent']) (defaults to: 'present')

    Sets whether to ensure facter.conf is present or absent

  • config_path (String[1]) (defaults to: '/etc/puppetlabs/facter')

    Path for configuring facter.conf

  • owner (String[1]) (defaults to: 'root')

    Owner of facter.conf file

  • group (String[1]) (defaults to: 'root')

    Group of facter.conf file

  • mode (String[1]) (defaults to: '0644')

    Mode of facter.conf file

  • facts_blocklist (Optional[Array[String[1]]]) (defaults to: undef)

    Optional array for setting facts to block

  • facts_ttls (Optional[Array[Hash]]) (defaults to: undef)

    Optional array of hashes for setting the time to live (ttl) for given facts. This will cache the facts listed for the given duration.

  • global_external_dir (Optional[Array[String[1]]]) (defaults to: undef)

    Optional array of paths to search in for external facts

  • global_custom_dir (Optional[Array[String[1]]]) (defaults to: undef)

    Optional array of paths to search in for custom facts

  • global_no_external_facts (Optional[Boolean]) (defaults to: undef)

    Optional boolean. If true, prevents Facter from searching for external facts.

  • global_no_custom_facts (Optional[Boolean]) (defaults to: undef)

    Optional boolean. If true, prevents Facter from searching for custom facts.

  • global_no_ruby (Optional[Boolean]) (defaults to: undef)

    Optional boolean. If true, prevents Facter from loading its Ruby functionality.

  • cli_debug (Optional[Boolean]) (defaults to: undef)

    Optional boolean. If true, Facter outputs debug messages.

  • cli_trace (Optional[Boolean]) (defaults to: undef)

    Optional boolean. If true, Facter prints stacktraces from errors arising in your custom facts.

  • cli_verbose (Optional[Boolean]) (defaults to: undef)

    Optional boolean. If true, Facter outputs its most detailed messages.

  • cli_log_level (Optional[ Enum[ 'none', 'fatal', 'error', 'warn', 'info', 'debug', 'trace' ] ]) (defaults to: undef)

    Sets the minimum level of message severity that gets logged. Valid options: “none”, “fatal”, “error”, “warn”, “info”, “debug”, “trace”.

  • fact_groups (Optional[ Array[ Struct[ { name => String[1], facts => Array[String[1]], } ] ] ]) (defaults to: undef)

    Definition of custom fact groups which can be used for blocking (blocklist) or caching (ttls) groups of facts.



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
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
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
# File 'manifests/init.pp', line 75

class facter_conf (
  Enum['present','absent']   $facter_conf_ensure = 'present',
  String[1]                  $config_path = '/etc/puppetlabs/facter',
  String[1]                  $owner = 'root',
  String[1]                  $group = 'root',
  String[1]                  $mode = '0644',
  Optional[Array[String[1]]] $facts_blocklist = undef,
  Optional[Array[Hash]]      $facts_ttls = undef,
  Optional[Array[String[1]]] $global_external_dir = undef,
  Optional[Array[String[1]]] $global_custom_dir = undef,
  Optional[Boolean]          $global_no_external_facts = undef,
  Optional[Boolean]          $global_no_custom_facts = undef,
  Optional[Boolean]          $global_no_ruby = undef,
  Optional[Boolean]          $cli_debug = undef,
  Optional[Boolean]          $cli_trace = undef,
  Optional[Boolean]          $cli_verbose = undef,
  Optional[
    Enum[
      'none',
      'fatal',
      'error',
      'warn',
      'info',
      'debug',
      'trace'
    ]
  ]                         $cli_log_level = undef,
  Optional[
    Array[
      Struct[
        {
          name => String[1],
          facts => Array[String[1]],
        }
      ]
    ]
  ]                          $fact_groups = undef,
) {
  $facter_conf_path = "${config_path}/facter.conf"
  $facter_conf_file_ensure = $facter_conf_ensure ? {
    'present' => file,
    default   => absent,
  }

  file { $config_path:
    ensure => directory,
    owner  => $owner,
    group  => $group,
    mode   => $mode,
  }

  file { $facter_conf_path:
    ensure => $facter_conf_file_ensure,
    owner  => $owner,
    group  => $group,
    mode   => $mode,
  }

  if $facter_conf_ensure == 'present' {
    if $facts_blocklist != undef {
      hocon_setting { 'facter_conf.facts.blocklist':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'facts.blocklist',
        type    => 'array',
        value   => $facts_blocklist,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.facts.blocklist':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'facts.blocklist',
        type    => 'array',
        require => File[$facter_conf_path],
      }
    }

    if $facts_ttls != undef {
      hocon_setting { 'facter_conf.facts.ttls':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'facts.ttls',
        type    => 'array',
        value   => $facts_ttls,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.facts.ttls':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'facts.ttls',
        type    => 'array',
        require => File[$facter_conf_path],
      }
    }

    if $global_external_dir != undef {
      hocon_setting { 'facter_conf.global.external-dir':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'global.external-dir',
        type    => 'array',
        value   => $global_external_dir,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.global.external-dir':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'global.external-dir',
        type    => 'array',
        require => File[$facter_conf_path],
      }
    }

    if $global_custom_dir != undef {
      hocon_setting { 'facter_conf.global.custom-dir':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'global.custom-dir',
        type    => 'array',
        value   => $global_custom_dir,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.global.custom-dir':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'global.custom-dir',
        type    => 'array',
        require => File[$facter_conf_path],
      }
    }

    if $global_no_external_facts != undef {
      hocon_setting { 'facter_conf.global.no-external-facts':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'global.no-external-facts',
        type    => 'boolean',
        value   => $global_no_external_facts,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.global.no-external-facts':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'global.no-external-facts',
        type    => 'boolean',
        require => File[$facter_conf_path],
      }
    }

    if $global_no_custom_facts != undef {
      hocon_setting { 'facter_conf.global.no-custom-facts':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'global.no-custom-facts',
        type    => 'boolean',
        value   => $global_no_custom_facts,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.global.no-custom-facts':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'global.no-custom-facts',
        type    => 'boolean',
        require => File[$facter_conf_path],
      }
    }

    if $global_no_ruby != undef {
      hocon_setting { 'facter_conf.global.no-ruby':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'global.no-ruby',
        type    => 'boolean',
        value   => $global_no_ruby,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.global.no-ruby':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'global.no-ruby',
        type    => 'boolean',
        require => File[$facter_conf_path],
      }
    }

    if $cli_debug != undef {
      hocon_setting { 'facter_conf.cli.debug':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'cli.debug',
        type    => 'boolean',
        value   => $cli_debug,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.cli.debug':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'cli.debug',
        type    => 'boolean',
        require => File[$facter_conf_path],
      }
    }

    if $cli_trace != undef {
      hocon_setting { 'facter_conf.cli.trace':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'cli.trace',
        type    => 'boolean',
        value   => $cli_trace,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.cli.trace':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'cli.trace',
        type    => 'boolean',
        require => File[$facter_conf_path],
      }
    }

    if $cli_verbose != undef {
      hocon_setting { 'facter_conf.cli.verbose':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'cli.verbose',
        type    => 'boolean',
        value   => $cli_verbose,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.cli.verbose':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'cli.verbose',
        type    => 'boolean',
        require => File[$facter_conf_path],
      }
    }

    if $cli_log_level != undef {
      hocon_setting { 'facter_conf.cli.log-level':
        ensure  => present,
        path    => $facter_conf_path,
        setting => 'cli.log-level',
        type    => 'string',
        value   => $cli_log_level,
        require => File[$facter_conf_path],
      }
    } else {
      hocon_setting { 'facter_conf.cli.log-level':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'cli.log-level',
        type    => 'string',
        require => File[$facter_conf_path],
      }
    }

    if $fact_groups != undef {
      $fact_groups.each | Struct[{ name => String[1], facts => Array[String[1]], }] $fact_group | {
        hocon_setting { "facter_conf.fact-groups.${fact_group['name']}":
          ensure  => present,
          path    => $facter_conf_path,
          setting => "fact-groups.${fact_group['name']}",
          type    => 'array',
          value   => $fact_group['facts'],
          require => File[$facter_conf_path],
        }
      }
    } else {
      hocon_setting { 'facter_conf.fact-groups':
        ensure  => absent,
        path    => $facter_conf_path,
        setting => 'fact-groups',
        type    => 'hash',
        require => File[$facter_conf_path],
      }
    }
  }
}