Puppet Class: psick::mariadb::root_password

Defined in:
manifests/mariadb/root_password.pp

Overview

Class: psick::mariadb::root_password

Set mariadb root password

Parameters:

  • root_cnf_template (String) (defaults to: 'psick/mariadb/root.my.cnf.erb')
  • password (Optional[Psick::Password]) (defaults to: $::psick::mariadb::root_password)


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
# File 'manifests/mariadb/root_password.pp', line 6

class psick::mariadb::root_password (
  String $root_cnf_template = 'psick/mariadb/root.my.cnf.erb',
  Optional[Psick::Password] $password = $::psick::mariadb::root_password,
) {

  if ! defined(File['/root/.my.cnf']) {
    file { '/root/.my.cnf':
      ensure  => 'present',
      path    => '/root/.my.cnf',
      mode    => '0400',
      content => template($root_cnf_template),
    }
  }

  file { '/root/.my.cnf.backup':
    ensure  => 'present',
    path    => '/root/.my.cnf.backup',
    mode    => '0400',
    content => template('psick/mariadb/root.my.cnf.backup.erb'),
    replace => false,
    before  => [Exec['mariadb_root_password'],
                Exec['mariadb_backup_root_my_cnf'] ],
  }

  exec { 'mariadb_backup_root_my_cnf':
    path    => '/bin:/sbin:/usr/bin:/usr/sbin',
    unless  => 'diff /root/.my.cnf /root/.my.cnf.backup',
    command => 'cp /root/.my.cnf /root/.my.cnf.backup ; true',
    before  => File['/root/.my.cnf'],
  }

  exec { 'mariadb_root_password':
    subscribe   => File['/root/.my.cnf'],
    path        => '/bin:/sbin:/usr/bin:/usr/sbin',
    refreshonly => true,
    command     => "mysqladmin --defaults-file=/root/.my.cnf.backup -uroot password '${psick::mariadb::root_password}'",
  }

}