class mysql::server( $rootpw = hiera('mysql::server::rootpw', ''), $implementation = 'mysql-server', # 'mariadb-server' ){ case $rootpw { '': { fail("You need to define a mysql root password! Please set mysql::server::rootpw config") } } include mysql $authentication_string = $::lsbdistid ? { 'ubuntu' => $::lsbdistcodename ? { 'trusty' => 'Password=PASSWORD', 'xenial' => $implementation ? { 'mysql-server' => 'authentication_string=password', default => 'Password=PASSWORD', }, }, default => 'Password=PASSWORD', } package { "mysql-server": name => $implementation, 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, } }