Defined Type: system::fact

Defined in:
manifests/fact.pp

Overview

Parameters:

  • value (Any) (defaults to: undef)
  • sys_schedule (Any) (defaults to: 'always')
  • type (Any) (defaults to: 'yaml')
  • ttl (Any) (defaults to: undef)


1
2
3
4
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
45
46
47
48
49
50
51
# File 'manifests/fact.pp', line 1

define system::fact (
  $value    = undef,
  $sys_schedule = 'always',
  $type     = 'yaml',
  $ttl      = undef,
) {
  # This uses facter_dot_d which is a Facter plugin that loads facts from
  # /etc/facter/facts.d
  $var = $title
  if is_array($value) {
    $resource_name = "${var}%index%"
    $parameters = {
      schedule => $sys_schedule,
      type     => $type,
      ttl      => $ttl,
    }
    $dynamic_parameters = {
      'value' => '%s',
    }
    $created_resource_hash =
      create_resources_hash_from($resource_name, $value, $parameters, $dynamic_parameters)
    create_resources('system::fact', $created_resource_hash)
  }
  else {
    case $type {
      'script': {
        file { "/etc/facter/facts.d/system_facts_${var}.sh":
          owner   => 'root',
          group   => 'root',
          mode    => '0744',
          content => $value,
        }
        if $ttl {
          file { "/etc/facter/facts.d/system_facts_${var}.sh.ttl":
            owner   => 'root',
            group   => 'root',
            mode    => '0744',
            content => "${ttl}\n",
          }
        }
      }
      default: {
        concat::fragment { "system_facts_${var}":
          target  => '/etc/facter/facts.d/system_facts.yaml',
          content => "${var}: ${value}\n",
          order   => '02',
        }
      }
    }
  }
}