Defined Type: psick::puppet::set_external_fact

Defined in:
manifests/puppet/set_external_fact.pp

Summary

Set an external fact via a file resource

Overview

This define creates an external fact as a file, so the fact value is not immediately available in the Puppet run when the fact is applied. (to have external facts immediately available place them in the facts directory of a module.

Parameters:

  • ensure (Enum['absent','present']) (defaults to: 'present')
  • value (Optional[Any]) (defaults to: undef)
  • template (Optional[String]) (defaults to: undef)
  • mode (String) (defaults to: '0644')
  • options (Hash) (defaults to: {})


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

define psick::puppet::set_external_fact (
  Enum['absent','present'] $ensure = 'present',
  Optional[Any] $value             = undef,
  Optional[String] $template       = undef,
  String $mode                     = '0644',
  Hash $options                    = {},
) {
  if ! $value and ! $template {
    fail('You must specify either a value or a template to use')
  }

  $external_facts_dir = $facts['kernel'] ? {
    'Windows' => 'C:\ProgramData\PuppetLabs\facter\facts.d',
    default   => '/etc/puppetlabs/facter/facts.d',
  }
  $file_content = $value ? {
    undef   => psick::template($template),
    default => "---\n  ${title}: ${value}\n",
  }
  $file_path = $value ? {
    undef   => "${external_facts_dir}/${title}",
    default => "${external_facts_dir}/${title}.yaml",
  }

  psick::tools::create_dir { "${external_facts_dir}_${title}":
    path   => $external_facts_dir,
    before => File[$file_path],
  }

  file { $file_path:
    ensure  => $ensure,
    content => $file_content,
    mode    => $mode,
  }
}