diff options
Diffstat (limited to 'modules/profile/manifests/postgresql/backup_pgbouncer.pp')
-rw-r--r-- | modules/profile/manifests/postgresql/backup_pgbouncer.pp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/modules/profile/manifests/postgresql/backup_pgbouncer.pp b/modules/profile/manifests/postgresql/backup_pgbouncer.pp new file mode 100644 index 0000000..45b8ed5 --- /dev/null +++ b/modules/profile/manifests/postgresql/backup_pgbouncer.pp | |||
@@ -0,0 +1,92 @@ | |||
1 | define profile::postgresql::backup_pgbouncer ( | ||
2 | String $base_path, | ||
3 | Hash $pg_infos, | ||
4 | String $pg_user = "postgres", | ||
5 | String $pg_group = "postgres", | ||
6 | ) { | ||
7 | include "profile::postgresql::pam_ldap_pgbouncer" | ||
8 | ensure_packages(["pgbouncer"]) | ||
9 | |||
10 | $host_cn = $title | ||
11 | |||
12 | $host = find_host($facts["ldapvar"]["other"], $host_cn) | ||
13 | if empty($host) { | ||
14 | fail("No host found for pgbouncer") | ||
15 | } elsif has_key($host["vars"], "host") { | ||
16 | $pg_backup_host = $host["vars"]["host"][0] | ||
17 | } else { | ||
18 | $pg_backup_host = $host["vars"]["real_hostname"][0] | ||
19 | } | ||
20 | |||
21 | $pg_path = "$base_path/$pg_backup_host/postgresql" | ||
22 | |||
23 | if has_key($host["vars"], "postgresql_backup_port") { | ||
24 | $pg_port = " port=${host[vars][postgresql_backup_port][0]}" | ||
25 | } else { | ||
26 | $pg_port = "" | ||
27 | } | ||
28 | |||
29 | # Config | ||
30 | ensure_resource("concat", "/etc/pgbouncer/pgbouncer.ini", { | ||
31 | mode => "0644", | ||
32 | owner => "root", | ||
33 | group => "root", | ||
34 | ensure_newline => true, | ||
35 | notify => Service["pgbouncer"], | ||
36 | before => Service["pgbouncer"], | ||
37 | }) | ||
38 | |||
39 | ensure_resource("concat::fragment", "pgbouncer_head", { | ||
40 | target => "/etc/pgbouncer/pgbouncer.ini", | ||
41 | order => 01, | ||
42 | source => "puppet:///modules/profile/postgresql/pgbouncer_head.ini", | ||
43 | }) | ||
44 | |||
45 | concat::fragment { "pgbouncer_$pg_backup_host": | ||
46 | target => "/etc/pgbouncer/pgbouncer.ini", | ||
47 | order => 02, | ||
48 | content => "${pg_infos[pgbouncer_dbname]} = host=$pg_path$pg_port user=${pg_infos[dbuser]} dbname=${pg_infos[dbname]}", | ||
49 | } | ||
50 | |||
51 | # pg_hba for accessed cluster | ||
52 | postgresql::server::pg_hba_rule { "$pg_backup_host - local access as ${pg_infos[dbuser]} user": | ||
53 | description => "Allow local access to ${pg_infos[dbuser]} user", | ||
54 | type => 'local', | ||
55 | database => $pg_infos["dbname"], | ||
56 | user => $pg_infos["dbuser"], | ||
57 | auth_method => 'trust', | ||
58 | order => "01-00", | ||
59 | target => "$pg_path/pg_hba.conf", | ||
60 | postgresql_version => "10", | ||
61 | } | ||
62 | |||
63 | # service | ||
64 | ensure_resource("file", "/etc/systemd/system/pgbouncer.service.d", { | ||
65 | ensure => "directory", | ||
66 | mode => "0644", | ||
67 | owner => "root", | ||
68 | group => "root", | ||
69 | }) | ||
70 | |||
71 | ensure_resource("file", "/etc/systemd/system/pgbouncer.service.d/override.conf", { | ||
72 | ensure => "present", | ||
73 | mode => "0644", | ||
74 | owner => "root", | ||
75 | group => "root", | ||
76 | content => "[Service]\nUser=\nUser=$pg_user\n", | ||
77 | notify => Service["pgbouncer"], | ||
78 | before => Service["pgbouncer"], | ||
79 | }) | ||
80 | |||
81 | ensure_resource("service", "pgbouncer", { | ||
82 | ensure => "running", | ||
83 | enable => true, | ||
84 | require => [ | ||
85 | Package["pgbouncer"], | ||
86 | File["/etc/systemd/system/pgbouncer.service.d/override.conf"], | ||
87 | Concat["/etc/pgbouncer/pgbouncer.ini"] | ||
88 | ], | ||
89 | }) | ||
90 | |||
91 | |||
92 | } | ||