summaryrefslogtreecommitdiff
path: root/manifests/puppetmasterd.pp
blob: aa428d56cdd3f927eac1df5254f4f75ec7adff7a (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# handles puppetmasterd service
class puppetmasterd {

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

  # 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 {
    "sqlite3":           ensure => installed;
    "libmysql-ruby":     ensure => installed;
    "ruby-hiera-puppet": ensure => $lsbdistcodename ? {
        'squeeze' => absent,
        default   => installed,
      }
  }

  case $puppetmaster_servertype {
    'mongrel': {
      include puppet::master::mongrel
    }
    'passenger': {
      include puppet::master::passenger
    }
    default: {
      service { "puppetmaster":
        enable     => true,
        ensure     => running,
        hasrestart => true,
        pattern    => 'puppet master',
        require    => Package['puppetmaster'],
      }
    }
  }

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

  file { "/etc/puppet/files":
    ensure  => directory,
    owner   => puppet,
    group   => puppet, 
    recurse => inf,
    require => User["puppet"],
  }

  file { "/etc/puppet/auth.conf":
    ensure  => file,
    owner   => puppet,
    group   => puppet, 
    require => User["puppet"],
  }

  file { "/etc/puppet/fileserver.conf":
    ensure  => file,
    owner   => puppet,
    group   => puppet, 
    require => User["puppet"],
  }

  # 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,
  }

  # cron rule to execute puppetlast once a week as a report
  # currently not working for puppet 2.6.x
  cron { "puppetlast":
    command  => "/usr/local/sbin/puppetlast",
    user     => root,
    hour     => "0",
    minute   => "0",
    weekday  => "0",
    ensure   => $puppetversion ? {
      "0.25.4" => present,
      default  => absent,
    },
    require  => File["/usr/local/sbin/puppetlast"],
  }

  # update config
  class { 'puppet::master::update': }
  
  # custom puppetlast command, thanks to immerda module:
  # http://git.puppet.immerda.ch/?p=module-puppet.git;a=summary
  #
  # right now it's not working, see
  # https://labs.riseup.net/code/issues/2515
  file { "/usr/local/sbin/puppetlast":
    source => "puppet:///modules/puppet/lastruncheck",
    ensure => absent,
    owner  => root,
    group  => root,
    mode   => 0700,
  }

  # 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,
  }
}