summaryrefslogtreecommitdiff
path: root/manifests/puppetmasterd.pp
blob: d574c8d4678a5dc9c460238a01be77a01dd94ada (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
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
# handles puppetmasterd service
class puppetmasterd {

  # Configuration
  case $puppetmaster_servertype {
    '': { 
      $puppetmaster_servertype  = 'mongrel'
      $puppetmaster_daemon_opts = '--ssl_client_header=HTTP_X_SSL_SUBJECT'
    }
  }

  case $puppetmaster_puppetmasters {
    '': { $puppetmaster_puppetmasters = '4' }
  }

  case $puppetmaster_port {
    '': { $puppetmaster_port = '18140' }
  }

  # Use this option if you want puppet to manage the certificates for all
  # master nodes, useful when using multiple masters as prevents issues such as
  # http://groups.google.com/group/puppet-users/browse_thread/thread/f24bd7500e9091bd
  #
  # The drawbacks are: 
  #
  #   - Such setup is more complete to manage when bootstrapping a fresh network.
  #   - It doesn't refresh the proxy server (eg. nginx) upon key updates.
  #
  # A better approach is to keep certificates at /etc/puppet/ssl (and hence at your puppet repo).
  if $puppetmaster_manage_ca == true {
    include puppetmaster::ca
  }

  # warns that this node has a puppetmaster
  $puppetmasterd_present = true

  # then include puppet class
  include puppetd

  # needed packages
  package {
    "puppetmaster":  ensure => installed;
    "sqlite3":       ensure => installed;
    "libmysql-ruby": ensure => installed;
  }

  file { "/etc/default/puppetmaster":
    ensure  => present,
    owner   => root,
    group   => root,
    mode    => 0644,
    content => template('puppet/puppetmaster.erb'),
    notify  => Service['puppetmaster'],
  }

  case $puppetmaster_servertype {
    'mongrel': {
      include nginx::puppetmaster

      case defined(Package["mongrel"]) {
        false: { package { "mongrel": ensure => installed, } }
      } 

      service { "puppetmaster":
        enable     => true,
        ensure     => running,
        hasrestart => true,
        require    => [ Package['puppetmaster'], Package['mongrel'], Service['nginx'] ],
      }
    }
    default: {
      service { "puppetmaster":
        enable     => true,
        ensure     => running,
        hasrestart => true,
        require    => Package['puppetmaster'],
      }
    }
  }

  # cron rule to update puppet config repository every 5 minutes
  cron { "puppet-update":
    command  => "/usr/local/sbin/update-puppet-conf.sh > /dev/null 2>&1",
    user     => puppet,
    minute   => "*/5",
    ensure   => present,
    require  => [ File["/usr/local/sbin/update-puppet-conf.sh"], User["puppet"] ],
  }

  # cron rule to execute puppetlast once a week as a report
  cron { "puppetlast":
    command  => "puppetlast",
    user     => root,
    hour     => "0",
    minute   => "0",
    weekday  => "0",
    ensure   => present,
  }

  # cron rule to restart puppetmaster before restarting the nodes
  cron { "puppetmaster-restart":
    command  => "/etc/init.d/puppetmaster restart > /dev/null 2>&1",
    user     => root,
    hour     => "*/1",
    minute   => "0",
    ensure   => absent,
  }

  # and the script to the cron-job above
  file { "/usr/local/sbin/update-puppet-conf.sh":
    source => "puppet://$server/modules/puppet/update-puppet-conf.sh",
    owner  => "puppet",
    group  => "puppet",
    mode   => 0755,
    ensure => present,
  }

  # for storeconfigs
  include mysql::server

  # Database creation as suggested by
  # http://reductivelabs.com/trac/puppet/wiki/Recipes/MySQLStoredConfiguration
  #exec { "create-storeconfigs-db":
  #    command         => "/usr/bin/mysqladmin create puppet",
  #    unless          => "/usr/bin/mysqlcheck -s puppet",
  #    notify          => Exec["create-storeconfigs-user"],
  #}
  #exec { "create-storeconfigs-user":
  #    command         => "/usr/bin/mysql -e 'grant all privileges on puppet.* to puppet@localhost identified by \"puppet\"'",
  #    refreshonly     => true,
  #}

}

class puppetmasterd::disabled inherits puppetmasterd {
  Service["puppetmaster"] {
    ensure => stopped,
  }

  Cron["puppetlast", "puppetmaster-restart", "puppet-update"] {
    ensure => absent,
  }
}