summaryrefslogtreecommitdiff
path: root/manifests/puppetd.pp
blob: b78cdde2bcd0b5153ce543c4de7807dc329f2d77 (plain)
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
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
# handles puppetd service
class puppetd inherits puppet {

  case $puppetmaster_port {
    '': { $puppetmaster_port = "8140" }
  }

  case $puppetd_runinterval {
    '': { $puppetd_runinterval = "7200" }
  }

  case $puppetd_configtimeout {
    '': { $puppetd_configtimeout = "120" }
  }

  case $puppetd_server {
    '': { $puppetd_server = "puppet.$domain" }
  }

  case $puppetd_ensure {
    '': { $puppetd_ensure = "installed" }
  }

  package { "puppet":
   ensure  => $puppetd_ensure,
   require => Package["cron"],
  }

  file { "/etc/default/puppet":
    source => "puppet://$server/modules/puppet/puppet",
    owner  => "root",
    group  => "root",
    mode   => 0644,
    ensure => present,
    notify => Service["puppet"],
  }

  service { "puppet":
    enable     => true,
    ensure     => running,
    hasrestart => true,
    require    => [ Package["puppet"], File["/etc/default/puppet"] ],
  }

  # name of puppet agent section in config file
  if $puppetversion <= "0.25.4" {
    $puppet_agent_name = 'puppetd'
  } else {
    $puppet_agent_name = 'agent'
  }

  # default config file for puppet nodes
  if ($puppetmasterd_present != true) or ($main_master != true) {
    file { "/etc/puppet/puppet.conf":
      ensure  => file,
      owner   => puppet,
      group   => puppet,
      content => template("puppet/puppet-node.conf.erb"),
    }
  } else {
    file { "/etc/puppet/puppet.conf":
      ensure  => file,
      owner   => puppet,
      group   => puppet,
    }
  }

  # cron rule to restart puppet minutes after puppetmaster is restarted
  cron { "puppet-restart":
    command  => "/etc/init.d/puppet restart > /dev/null 2>&1",
    user     => root,
    hour     => "*/1",
    minute   => "10",
    ensure   => absent,
    require  => Service["puppet"],
  }

  file { "/usr/local/sbin/check-puppetd.sh":
    content => template("puppet/check-puppetd.sh.erb"),
    owner   => "puppet",
    group   => "puppet",
    mode    => 0755,
    ensure  => present,
  }

  cron { "puppetd-check":
    command  => "/usr/local/sbin/check-puppetd.sh > /dev/null",
    user     => root,
    hour     => "*/1",
    minute   => "0",
    require  => File["/usr/local/sbin/check-puppetd.sh"],
    ensure   => present,
  }

  # thanks to https://labs.riseup.net/code/projects/shared-puppet
  file { "/etc/cron.d/puppetd":
    source => "puppet://$server/modules/puppet/cron.d/puppetd",
    owner  => root,
    group  => root,
    mode   => 0644;
  }

  # restore to original state after the following bug is addressed:
  # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=625626
  if $lsbdistcodename == 'squeeze' {
    file { "/etc/logrotate.d/puppetmaster":
      ensure => absent,
    }
  }
}