File: mysql.pp

package info (click to toggle)
puppet-module-openstacklib 25.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 968 kB
  • sloc: ruby: 4,500; python: 38; sh: 22; makefile: 10
file content (117 lines) | stat: -rw-r--r-- 3,849 bytes parent folder | download
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
# == Definition: openstacklib::db::mysql
#
# This resource configures a mysql database for an OpenStack service
#
# == Parameters:
#
#  [*password*]
#    Password to use for the database user for this service;
#    string; required
#
#  [*plugin*]
#    Authentication plugin to use when connecting to the MySQL server;
#    string; optional; default to 'undef'
#
#  [*dbname*]
#    The name of the database
#    string; optional; default to the $title of the resource, i.e. 'nova'
#
#  [*user*]
#    The database user to create;
#    string; optional; default to the $title of the resource, i.e. 'nova'
#
#  [*host*]
#    The IP address or hostname of the user in mysql_grant;
#    string; optional; default to '127.0.0.1'
#
#  [*charset*]
#    The charset to use for the database;
#    string; optional; default to 'utf8'
#
#  [*collate*]
#    The collate to use for the database;
#    string; optional; default to 'utf8_general_ci'
#
#  [*allowed_hosts*]
#    Additional hosts that are allowed to access this database;
#    array or string; optional; default to undef
#
#  [*privileges*]
#    Privileges given to the database user;
#    string or array of strings; optional; default to 'ALL'
#
#  [*create_user*]
#    Flag to allow for the skipping of the user as part of the database setup.
#    Set to false to skip the user creation.
#    Defaults to true.
#
#  [*create_grant*]
#    Flag to allow for the skipping of the user grants as part of the database
#    setup. Set to false to skip the user creation.
#    Defaults to true.
#
#  [*tls_options*]
#    The TLS options that the user will have
#    Defaults to ['NONE']
#
# DEPRECATED PARAMETERS
#
#  [*password_hash*]
#    Password hash to use for the database user for this service;
#    string; optional; default to undef
#
define openstacklib::db::mysql (
  Optional[String[1]] $password                       = undef,
  Optional[String[1]] $plugin                         = undef,
  String[1] $dbname                                   = $title,
  String[1] $user                                     = $title,
  String[1] $host                                     = '127.0.0.1',
  String[1] $charset                                  = 'utf8',
  String[1] $collate                                  = 'utf8_general_ci',
  Variant[String[1], Array[String[1]]] $allowed_hosts = [],
  Variant[String[1], Array[String[1]]] $privileges    = 'ALL',
  Boolean $create_user                                = true,
  Boolean $create_grant                               = true,
  Variant[String[1], Array[String[1]]] $tls_options   = ['NONE'],
  # DEPRECATED PARAMETER
  Optional[String[1]] $password_hash                  = undef,
) {

  include mysql::server
  include mysql::client

  if $password_hash != undef {
    warning("The password_hash parameter was deprecated and will be removed \
in a future release. Use password instead")
    $password_hash_real = $password_hash
  } elsif $password != undef {
    $password_hash_real = mysql::password($password)
  } else {
    fail('password should be set')
  }

  mysql_database { $dbname:
    ensure  => present,
    charset => $charset,
    collate => $collate,
  }

  Class['mysql::server'] ~> Mysql_database<| title == $dbname |>
  Class['mysql::client'] ~> Mysql_database<| title == $dbname |>

  if $create_user or $create_grant {
    $allowed_hosts_list = unique(concat(any2array($allowed_hosts), [$host]))
    $real_allowed_hosts = prefix($allowed_hosts_list, "${dbname}_")

    openstacklib::db::mysql::host_access { $real_allowed_hosts:
      user          => $user,
      plugin        => $plugin,
      password_hash => $password_hash_real,
      database      => $dbname,
      privileges    => $privileges,
      create_user   => $create_user,
      create_grant  => $create_grant,
      tls_options   => $tls_options,
    }
  }
}