Puppet Class: mcollective::facts

Defined in:
manifests/facts.pp

Overview

Parameters:

  • libdir (String) (defaults to: $mcollective::libdir)
  • rubypath (String) (defaults to: $mcollective::rubypath)
  • configdir (String) (defaults to: $mcollective::configdir)
  • factspath (String) (defaults to: $mcollective::factspath)
  • refresh_interval (Integer) (defaults to: $mcollective::facts_refresh_interval)
  • owner (Optional[String]) (defaults to: $mcollective::plugin_owner)
  • group (Optional[String]) (defaults to: $mcollective::plugin_group)
  • pidfile (Optional[String]) (defaults to: $mcollective::facts_pidfile)
  • server (Boolean) (defaults to: $mcollective::server)


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
52
53
54
55
56
57
58
59
60
61
62
# File 'manifests/facts.pp', line 1

class mcollective::facts (
  String $libdir = $mcollective::libdir,
  String $rubypath = $mcollective::rubypath,
  String $configdir = $mcollective::configdir,
  String $factspath = $mcollective::factspath,
  Integer $refresh_interval = $mcollective::facts_refresh_interval,
  Optional[String] $owner = $mcollective::plugin_owner,
  Optional[String] $group = $mcollective::plugin_group,
  Optional[String] $pidfile = $mcollective::facts_pidfile,
  Boolean $server = $mcollective::server
) {
  $scriptpath = "${libdir}/mcollective/refresh_facts.rb"

  file{$scriptpath:
    owner   => $owner,
    group   => $group,
    mode    => "0775",
    content => template("mcollective/refresh_facts.erb"),
  }

  if $refresh_interval > 0 and $server {
    $cron_ensure = "present"
    $cron_offset = "00:${sprintf("%02d", fqdn_rand($refresh_interval, 'facts cronjob'))}"
    $cron_minutes = mcollective::crontimes(fqdn_rand($refresh_interval, 'facts cronjob'), $refresh_interval, 60)
    $creates = $factspath

    exec{"mcollective_facts_yaml_refresh":
      command => "\"${rubypath}\" \"${scriptpath}\" -o \"${factspath}\"",
      creates => $creates,
      require => Class["mcollective::config"]
    }
  } else {
    $cron_ensure = "absent"
    $cron_offset = "00:00"
    $cron_minutes = "0"
    $creates = undef # always run via puppet when opted out of cron option
  }

  if $pidfile {
    $factspid = "-p '${pidfile}'"
  }

  if $facts["os"]["family"] == "windows" {
    # on windows task scheduler prevent dupes already so no need to handle the PID here
    scheduled_task{"mcollective_facts_yaml_refresh":
      ensure    => $cron_ensure,
      command   => $rubypath,
      arguments => "'${scriptpath}' -o '${factspath}'",
      trigger   => {
        "schedule"         => "daily",
        "start_time"       => $cron_offset,
        "minutes_interval" => $refresh_interval
      }
    }
  } else {
    cron{"mcollective_facts_yaml_refresh":
      ensure  => $cron_ensure,
      command => "'${rubypath}' '${scriptpath}' -o '${factspath}' ${factspid} &> /dev/null",
      minute  => $cron_minutes
    }
  }
}