summaryrefslogtreecommitdiff
path: root/manifests/server.pp
blob: 788654f6f164bb8a218c5588e252197bbb8260fa (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
class mysql::server(
  $rootpw = hiera('mysql::server::rootpw', '')
){
  case $rootpw {
    '': { fail("You need to define a mysql root password! Please set mysql::server::rootpw config") }
  }

  include mysql

  package { "mysql-server":
    ensure => installed,
  }

  service { "mysql":
    ensure     => running,
    enable     => true,
    hasrestart => true,
    hasstatus  => true,
    require    => Package["mysql-server"],
  }

  file { '/usr/local/sbin/setmysqlpass.sh':
    content => template('mysql/setmysqlpass.sh.erb'),
    require => [ Service['mysql'], Mysql::Cnf['root'] ],
    owner   => root,
    group   => root,
    mode    => '0500',
    notify  => Exec['set_mysql_rootpw'],
  } 

  exec { 'set_mysql_rootpw':
    command     => "/usr/local/sbin/setmysqlpass.sh",
    require     => [ File['/usr/local/sbin/setmysqlpass.sh'], Package[mysql-server] ],
    refreshonly => true,
    user        => root,
  }

  mysql::cnf { "root":
    home   => "/root",
    passwd => $rootpw,
  }
}