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
|
# File 'manifests/replication.pp', line 1
class postgresplus::replication (
$user = $postgresplus::user,
$repl_mode = $postgresplus::repl_mode,
$replication = $postgresplus::replication,
$repl_mode = $postgresplus::repl_mode,
$repl_user = $postgresplus::repl_user,
$repl_pass = $postgresplus::repl_pass,
$datadir = $postgresplus::datadir,
$bindir = $postgresplus::bindir,
$serverport = $postgresplus::serverport,
$repl_target_address = pick($postgresplus::repl_target_address, 'all'),
$repl_auth_method = pick($postgresplus::repl_auth_method , 'trust'),
$ppa_service = $postgresplus::ppa_service,
) {
$recovery_conf = "${datadir}/recovery.conf"
if ( $repl_mode != false) {
if ( $repl_mode == 'master' ) {
if ( $repl_target_address != undef ) {
notify { "setting up tags for target" :}
@@exec { 'create_postgres_target':
cwd => '/tmp',
command => "${bindir}/pg_basebackup -h ${ipaddress} -U ${repl_user} -D ${datadir} -c fast -Xs ",
notify => [
Service[ $ppa_service ],
],
tag => 'create_postgres_target',
# before => Exec["setup perms on DB files"],
onlyif => "/usr/bin/test ! -f ${recovery_conf}",
}
@@file { "${recovery_conf}" :
ensure => file,
content => template('postgresplus/recovery.conf.erb'),
tag => "recovery_conf",
before => Exec["setup perms on DB files"],
}
postgresplus::hba_config { 'allow replication access':
description => "Open up postgresql for replication PPAS",
type => 'host',
database => 'replication',
user => "${repl_user}",
address => "${repl_target_address}",
auth_method => "${repl_auth_method}",
}->
postgresplus::hba_config { 'allow local trust access':
type => 'local',
database => 'all',
user => 'all',
auth_method => 'trust',
description => "Open up postgresql for local trust access",
}->
postgresplus::role { "${repl_user}":
replication => true,
password_hash => postgresql_password ( "${repl_user}", "mypassword" ),
}
}
} else {
if ( $repl_mode == 'target' ) {
exec {'stop replication target server' :
command => "/sbin/service ${postgresplus::ppa_service} stop ; /bin/true",
onlyif => "/usr/bin/test ! -f ${recovery_conf}",
} ->
exec {'remove non replicated database' :
command => "/bin/rm -fr ${datadir}/* ",
onlyif => "/usr/bin/test ! -f ${recovery_conf}",
} ->
notify { "applying tags to target" :} ->
Exec <<| tag == 'create_postgres_target' |>> ->
File <<| tag == "recovery_conf" |>> ->
exec {'setup perms on DB files' :
command => "/bin/chown -R ${postgresplus::user}:${postgresplus::group} ${datadir}",
} ->
service { $ppa_service :
ensure => running,
enable => true
}
}
}
}
}
|