init.pp 8.26 KB
Newer Older
Hugo Hörnquist's avatar
Hugo Hörnquist committed
1
2
3
class datorhandbok (
  $mysql_password = undef, # hiera
) {
Hugo Hörnquist's avatar
Hugo Hörnquist committed
4
  ensure_packages([
Hugo Hörnquist's avatar
fixes    
Hugo Hörnquist committed
5
    'apache2',
6
    'default-mysql-server',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
7
8
9
    'mediawiki',
    'imagemagick',
    ],
Hugo Hörnquist's avatar
Hugo Hörnquist committed
10
    { ensure => installed, })
Hugo Hörnquist's avatar
Hugo Hörnquist committed
11
12

  service { 'apache2':
Hugo Hörnquist's avatar
Hugo Hörnquist committed
13
14
15
    ensure  => running,
    enable  => true,
    require => Package['apache2'],
Hugo Hörnquist's avatar
Hugo Hörnquist committed
16
17
18
  }

  service { 'mysql':
Hugo Hörnquist's avatar
Hugo Hörnquist committed
19
20
21
    ensure  => running,
    enable  => true,
    require => Package['default-mysql-server'],
Hugo Hörnquist's avatar
Hugo Hörnquist committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  }


  #  ┌───────────────────────────────┤ Configuring mariadb-server-10.1 ├───────────────────────────────┐
  #  │                                                                                                 │
  #  │ Important note for NIS/YP users                                                                 │
  #  │                                                                                                 │
  #  │ Using MariaDB under NIS/YP requires a mysql user account to be added on the local system with:  │
  #  │                                                                                                 │
  #  │  adduser --system --group --home /var/lib/mysql mysql                                           │
  #  │                                                                                                 │
  #  │                                                                                                 │
  #  │ You should also check the permissions and ownership of the /var/lib/mysql directory:            │
  #  │                                                                                                 │
  #  │  /var/lib/mysql: drwxr-xr-x   mysql    mysql                                                    │
  #  │                                                                                                 │
  #  │                                             <Ok>                                                │
  #  │                                                                                                 │
  #  └─────────────────────────────────────────────────────────────────────────────────────────────────┘
Hugo Hörnquist's avatar
Hugo Hörnquist committed
41
42
43
44
45
46
47
48
49
  # Mariadb gave the following notice on upgrade. Might as well
  # explicitly specifify it here

  group { 'mysql':
    ensure => present,
    system => true,
  }

  user { 'mysql':
Hugo Hörnquist's avatar
Hugo Hörnquist committed
50
51
52
53
    ensure => present,
    system => true,
    gid    => 'mysql',
    home   => '/var/lib/mysql',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
54
55
56
57
58
59
60
61
  }

  file { '/var/lib/mysql':
    ensure => directory,
    owner  => mysql,
    group  => mysql,
    mode   => '0755',
  }
Hugo Hörnquist's avatar
Hugo Hörnquist committed
62

63
64
65
66
67
68
69
70
  ensure_packages (['logrotate'],
    { ensure => installed })

  file { '/etc/logrotate.d/datorhandbok-mysql':
    ensure => file,
    source => 'puppet:///modules/datorhandbok/logrotate',
  }

71
72
  file { '/var/lib/mysql-dump/run.sh':
    ensure => file,
73
    mode   => '0755',
74
75
76
    source => 'puppet:///modules/datorhandbok/mysql-dump.sh',
  }

Hugo Hörnquist's avatar
Hugo Hörnquist committed
77
  cron { 'backup-mysql':
78
    command => '/var/lib/mysql-dump/run.sh',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    user    => 'root',
    hour    => 3,
    minute  => 11;

  }

  file { '/etc/apache2/mods-enabled/rewrite.load':
      ensure  => symlink,
      target  => '/etc/apache2/mods-available/rewrite.load',
      owner   => root,
      group   => root,
      notify  => Service['apache2'],
      require => Package['apache2'],
  }

  file { '/etc/apache2/mods-enabled/ssl.load':
      ensure  => symlink,
      target  => '/etc/apache2/mods-available/ssl.load',
      owner   => root,
      group   => root,
      notify  => Service['apache2'],
      require => Package['apache2'],
  }

103
104
105
106
107
108
  class { '::letsencrypt':
    email => 'root@lysator.liu.se',
  }

  ensure_packages ([
    'cronic',
109
    'python3-certbot-apache',
110
111
112
113
    ],
    { ensure => installed })

  letsencrypt::certonly { $facts['networking']['fqdn']:
Hugo Hörnquist's avatar
Hugo Hörnquist committed
114
    domains             => [ $facts['networking']['fqdn'] ],
115
116
117
118
119
    manage_cron         => true,
    cron_hour           => [2, 14],
    cron_minute         => 13,
    plugin              => 'apache',
    letsencrypt_command => 'cronic certbot',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
120
121
122
123
124
125
126
127
128
  }

  file { '/etc/apache2/sites-available/datorhandbok.lysator.liu.se.conf':
      ensure  => file,
      owner   => root,
      group   => root,
      mode    => '0444',
      notify  => Service['apache2'],
      require => Package['apache2'],
Hugo Hörnquist's avatar
Hugo Hörnquist committed
129
      content => epp('datorhandbok/datorhandbok.lysator.liu.se',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
130
        {
Hugo Hörnquist's avatar
Hugo Hörnquist committed
131
132
133
134
135
136
          # 'sslcertificatefile'      => '/etc/ssl/certs/datorhandbok.lysator.liu.se/datorhandbok.lysator.liu.se.pem',
          # 'sslcertificatekeyfile'   => '/etc/ssl/certs/datorhandbok.lysator.liu.se/datorhandbok.lysator.liu.se.key',
          # 'sslcertificatechainfile' => '/etc/ssl/certs/DigiCertCA.crt',
          'sslcertificatefile'      => "/etc/letsencrypt/live/${facts['networking']['fqdn']}/fullchain.pem",
          'sslcertificatekeyfile'   => "/etc/letsencrypt/live/${facts['networking']['fqdn']}/privkey.pem",
          'sslcertificatechainfile' => "/etc/letsencrypt/live/${facts['networking']['fqdn']}/fullchain.pem",
Hugo Hörnquist's avatar
Hugo Hörnquist committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
        }),
  }

  file { '/etc/apache2/sites-enabled/datorhandbok.lysator.liu.se.conf':
    ensure  => symlink,
    target  => '/etc/apache2/sites-available/datorhandbok.lysator.liu.se.conf',
    owner   => root,
    group   => root,
    notify  => Service['apache2'],
    require => File['/etc/apache2/sites-available/datorhandbok.lysator.liu.se.conf'],
  }

  file { '/etc/apache2/sites-enabled/000-default':
    ensure => absent,
    notify => Service['apache2'],
  }

Hugo Hörnquist's avatar
Hugo Hörnquist committed
154
155
156
157
158
  file { '/etc/mediawiki/LocalSettings.php':
    ensure  => file,
    owner   => root,
    group   => www-data,
    mode    => '0440',
Hugo Hörnquist's avatar
fixes    
Hugo Hörnquist committed
159
    content => epp('datorhandbok/LocalSettings.php',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
160
161
162
      # Wrapping $mysql_password in Sensitive() would prevent it from
      # showing up in logs, but the file then contained
      # "Sensitive [value redacted]"...
Hugo Hörnquist's avatar
Hugo Hörnquist committed
163
      { 'mysql_password' => $mysql_password }),
Hugo Hörnquist's avatar
Hugo Hörnquist committed
164
165
    require => Package['mediawiki'],
  }
Hugo Hörnquist's avatar
Hugo Hörnquist committed
166
167
168
169
170

  file { '/var/lib/mediawiki/skins/lyslogo-liten.png':
    ensure  => file,
    owner   => www-data,
    group   => www-data,
Hugo Hörnquist's avatar
Hugo Hörnquist committed
171
    source  => 'puppet:///modules/datorhandbok/lyslogo-liten.png',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
172
173
174
175
176
177
178
    require => Package['mediawiki'],
  }

  file { '/var/lib/mediawiki/favicon.ico':
    ensure  => file,
    owner   => root,
    group   => root,
Hugo Hörnquist's avatar
Hugo Hörnquist committed
179
    source  => 'puppet:///modules/datorhandbok/favicon.ico',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
180
181
182
    require => Package['mediawiki'],
  }

Hugo Hörnquist's avatar
Hugo Hörnquist committed
183
184
185
186
187
188
189
  # Set in CASAuthSettings as redirect location on failed login
  file { '/var/lib/mediawiki/login-error.php':
    ensure  => file,
    source  => 'puppet:///modules/datorhandbok/login-error.php',
    require => Package['mediawiki'],
  }

Hugo Hörnquist's avatar
Hugo Hörnquist committed
190
191
192
193
194
  file { '/etc/php/7.3/apache2/conf.d/20-curl.ini':
    ensure => link,
    target => '/etc/php/7.3/mods-available/curl.ini',
  }

Hugo Hörnquist's avatar
Hugo Hörnquist committed
195

Hugo Hörnquist's avatar
Hugo Hörnquist committed
196
197
198
199
200
201
202
203
204
205
206
  # mods-enabled/php* might need to be removed

  file { '/etc/apache2/mods-enabled/php7.3.conf':
    ensure => link,
    target => '../mods-available/php7.3.conf',
  }

  file { '/etc/apache2/mods-enabled/php7.3.load':
    ensure => link,
    target => '../mods-available/php7.3.load',
  }
Hugo Hörnquist's avatar
Hugo Hörnquist committed
207

208
209
210
211
212
  file { '/var/lib/mediawiki/extensions/CASAuth/':
    ensure => link,
    target => '/opt/CASAuth-master',
  }

Hugo Hörnquist's avatar
Hugo Hörnquist committed
213
  archive { '/opt/master.tar.gz':
Hugo Hörnquist's avatar
...    
Hugo Hörnquist committed
214
215
216
217
218
    ensure       => present,
    url          => 'https://github.com/CWRUChielLab/CASAuth/archive/master.tar.gz',
    creates      => '/opt/CASAuth-master',
    extract_path => '/opt',
    extract      => true,
219
220
221
222
223
  }

  file { '/var/lib/mediawiki/extensions/CASAuth/CAS/':
    ensure => link,
    target => '/opt/CAS-1.3.8',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
224
225
  }

Hugo Hörnquist's avatar
Hugo Hörnquist committed
226
  archive { '/opt/CAS-1.3.8.tgz':
Hugo Hörnquist's avatar
Hugo Hörnquist committed
227
228
229
    ensure       => present,
    url          => 'https://github.com/apereo/phpCAS/releases/download/1.3.8/CAS-1.3.8.tgz',
    creates      => '/opt/CAS-1.3.8',
Hugo Hörnquist's avatar
...    
Hugo Hörnquist committed
230
    extract_path => '/opt',
Hugo Hörnquist's avatar
Hugo Hörnquist committed
231
    extract      => true,
Hugo Hörnquist's avatar
Hugo Hörnquist committed
232
233
234
235
236
237
238
  }

  file { '/var/lib/mediawiki/extensions/CASAuth/CASAuthSettings.php':
    ensure => file,
    source => 'puppet:///modules/datorhandbok/CASAuthSettings.php',
  }

Hugo Hörnquist's avatar
Hugo Hörnquist committed
239
240
241
242
243
244
  file { '/etc/mediawiki-extensions/extensions-enabled/RSSReader.php':
    ensure  => symlink,
    target  => '/etc/mediawiki-extensions/extensions-available/RSSReader.php',
    require => Package['mediawiki'],
  }
}