Skip to content

Commit b68da38

Browse files
authored
Merge pull request #275 from ody/get_psql_version
Fetch installed PSQL version
2 parents f32d1c5 + 076cc7f commit b68da38

File tree

6 files changed

+79
-36
lines changed

6 files changed

+79
-36
lines changed

metadata.json

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
{
4040
"name": "puppetlabs/inifile",
4141
"version_requirement": ">= 5.2.0 < 6.0.0"
42+
},
43+
{
44+
"name": "puppetlabs/ruby_task_helper",
45+
"version_requirement": ">= 0.6.1 < 1.0.0"
4246
}
4347
],
4448
"operatingsystem_support": [

plans/add_compiler.pp

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,25 @@
4444
}
4545
}
4646

47+
# On the PostgreSQL server backing PuppetDB for compiler, get version number
48+
$psql_version = run_task('peadm::get_psql_version', $primary_postgresql_target).first.value['version']
49+
4750
# Add the following two lines to /opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf
4851
#
4952
# pe-puppetdb-pe-puppetdb-map <new-compiler-host> pe-puppetdb
5053
# pe-puppetdb-pe-puppetdb-migrator-map <new-compiler-host> pe-puppetdb-migrator
5154

5255
apply($primary_postgresql_target) {
5356
file_line { 'pe-puppetdb-pe-puppetdb-map':
54-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
57+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf",
5558
line => "pe-puppetdb-pe-puppetdb-map ${compiler_target.peadm::certname()} pe-puppetdb",
5659
}
5760
file_line { 'pe-puppetdb-pe-puppetdb-migrator-map':
58-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
61+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf",
5962
line => "pe-puppetdb-pe-puppetdb-migrator-map ${compiler_target.peadm::certname()} pe-puppetdb-migrator",
6063
}
6164
file_line { 'pe-puppetdb-pe-puppetdb-read-map':
62-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
65+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf",
6366
line => "pe-puppetdb-pe-puppetdb-read-map ${compiler_target.peadm::certname()} pe-puppetdb-read",
6467
}
6568
}

plans/add_replica.pp

+26-20
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,34 @@
6060
dns_alt_names => $dns_alt_names
6161
)
6262

63-
# On the PE-PostgreSQL server in the <replacement-avail-group-letter> group
64-
65-
# Stop puppet and add the following two lines to
66-
# /opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf
67-
# pe-puppetdb-pe-puppetdb-map <replacement-replica-fqdn> pe-puppetdb
68-
# pe-puppetdb-pe-puppetdb-migrator-map <replacement-replica-fqdn> pe-puppetdb-migrator
69-
apply($replica_postgresql_target) {
70-
file_line { 'pe-puppetdb-pe-puppetdb-map':
71-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
72-
line => "pe-puppetdb-pe-puppetdb-map ${replica_target.peadm::certname()} pe-puppetdb",
63+
# Wrap these things that operate on replica_postgresql_target in an if statement
64+
# to avoid failures retrieving PSQL version because you can't operate functions
65+
# on a return value of nil.
66+
if $replica_postgresql_host {
67+
# On the PE-PostgreSQL server in the <replacement-avail-group-letter> group
68+
$psql_version = run_task('peadm::get_psql_version', $replica_postgresql_target).first.value['version']
69+
70+
# Stop puppet and add the following two lines to
71+
# /opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf
72+
# pe-puppetdb-pe-puppetdb-map <replacement-replica-fqdn> pe-puppetdb
73+
# pe-puppetdb-pe-puppetdb-migrator-map <replacement-replica-fqdn> pe-puppetdb-migrator
74+
apply($replica_postgresql_target) {
75+
file_line { 'pe-puppetdb-pe-puppetdb-map':
76+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf",
77+
line => "pe-puppetdb-pe-puppetdb-map ${replica_target.peadm::certname()} pe-puppetdb",
78+
}
79+
file_line { 'pe-puppetdb-pe-puppetdb-migrator-map':
80+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf",
81+
line => "pe-puppetdb-pe-puppetdb-migrator-map ${replica_target.peadm::certname()} pe-puppetdb-migrator",
82+
}
83+
file_line { 'pe-puppetdb-pe-puppetdb-read-map':
84+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf",
85+
line => "pe-puppetdb-pe-puppetdb-read-map ${replica_target.peadm::certname()} pe-puppetdb-read",
86+
}
7387
}
74-
file_line { 'pe-puppetdb-pe-puppetdb-migrator-map':
75-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
76-
line => "pe-puppetdb-pe-puppetdb-migrator-map ${replica_target.peadm::certname()} pe-puppetdb-migrator",
77-
}
78-
file_line { 'pe-puppetdb-pe-puppetdb-read-map':
79-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
80-
line => "pe-puppetdb-pe-puppetdb-read-map ${replica_target.peadm::certname()} pe-puppetdb-read",
81-
}
82-
}
8388

84-
run_command('systemctl reload pe-postgresql.service', $replica_postgresql_target)
89+
run_command('systemctl reload pe-postgresql.service', $replica_postgresql_target)
90+
}
8591

8692
run_plan('peadm::util::update_classification', $primary_target,
8793
server_a_host => $replica_avail_group_letter ? { 'A' => $replica_host, default => undef },

plans/subplans/db_populate.pp

+22-13
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717
$destination_target,
1818
]))
1919

20-
# Add the following two lines to /opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf
20+
# Retrieve source's PSQL version
21+
$psql_version = run_task('peadm::get_psql_version', $source_target).first.value['version']
22+
23+
# Determine clientcert setting
24+
$clientcert = $psql_version ? {
25+
'14' => 'verify-full',
26+
default => 1
27+
}
28+
29+
# Add the following two lines to /opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf
2130
#
2231
# These lines allow connections from destination by pg_basebackup to replicate
2332
# content
2433
apply($source_target) {
2534
file_line { 'replication-pe-ha-replication-map':
26-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
35+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf",
2736
line => "replication-pe-ha-replication-map ${destination_target.peadm::certname()} pe-ha-replication",
2837
}
2938
file_line { 'replication-pe-ha-replication-ipv4':
30-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_hba.conf',
31-
line => 'hostssl replication pe-ha-replication 0.0.0.0/0 cert map=replication-pe-ha-replication-map clientcert=1',
39+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_hba.conf",
40+
line => "hostssl replication pe-ha-replication 0.0.0.0/0 cert map=replication-pe-ha-replication-map clientcert=${clientcert}",
3241
}
3342
file_line { 'replication-pe-ha-replication-ipv6':
34-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_hba.conf',
35-
line => 'hostssl replication pe-ha-replication ::/0 cert map=replication-pe-ha-replication-map clientcert=1',
43+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_hba.conf",
44+
line => "hostssl replication pe-ha-replication ::/0 cert map=replication-pe-ha-replication-map clientcert=${clientcert}",
3645
}
3746
}
3847

@@ -42,15 +51,15 @@
4251
# Save existing certificates to use for authentication to source. Can not use
4352
# certs stored in /etc/puppetlabs/puppet/ssl because we will run pg_basebackup
4453
# as pe-postgres user, which lacks access
45-
run_command('mv /opt/puppetlabs/server/data/postgresql/11/data/certs /opt/puppetlabs/server/data/pg_certs', $destination_target)
54+
run_command("mv /opt/puppetlabs/server/data/postgresql/${psql_version}/data/certs /opt/puppetlabs/server/data/pg_certs", $destination_target)
4655

4756
# pg_basebackup requires an entirely empty data directory
4857
run_command('rm -rf /opt/puppetlabs/server/data/postgresql/*', $destination_target)
4958

5059
$pg_basebackup = @("PGBASE")
5160
runuser -u pe-postgres -- \
5261
/opt/puppetlabs/server/bin/pg_basebackup \
53-
-D /opt/puppetlabs/server/data/postgresql/11/data \
62+
-D /opt/puppetlabs/server/data/postgresql/${psql_version}/data \
5463
-d "host=${source_host}
5564
user=pe-ha-replication
5665
sslmode=verify-full
@@ -72,18 +81,18 @@
7281
apply($source_target) {
7382
file_line { 'replication-pe-ha-replication-map':
7483
ensure => absent,
75-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_ident.conf',
84+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_ident.conf",
7685
line => "replication-pe-ha-replication-map ${destination_target.peadm::certname()} pe-ha-replication",
7786
}
7887
file_line { 'replication-pe-ha-replication-ipv4':
7988
ensure => absent,
80-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_hba.conf',
81-
line => 'hostssl replication pe-ha-replication 0.0.0.0/0 cert map=replication-pe-ha-replication-map clientcert=1',
89+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_hba.conf",
90+
line => "hostssl replication pe-ha-replication 0.0.0.0/0 cert map=replication-pe-ha-replication-map clientcert=${clientcert}",
8291
}
8392
file_line { 'replication-pe-ha-replication-ipv6':
8493
ensure => absent,
85-
path => '/opt/puppetlabs/server/data/postgresql/11/data/pg_hba.conf',
86-
line => 'hostssl replication pe-ha-replication ::/0 cert map=replication-pe-ha-replication-map clientcert=1',
94+
path => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/pg_hba.conf",
95+
line => "hostssl replication pe-ha-replication ::/0 cert map=replication-pe-ha-replication-map clientcert=${clientcert}",
8796
}
8897
}
8998

tasks/get_psql_version.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"description": "Run on a PE PSQL node to return the major version of the PSQL server currently installed",
3+
"parameters": { },
4+
"files": ["ruby_task_helper/files/task_helper.rb"],
5+
"input_method": "stdin"
6+
}

tasks/get_psql_version.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/opt/puppetlabs/puppet/bin/ruby
2+
# frozen_string_literal: true
3+
4+
require_relative '../../ruby_task_helper/files/task_helper.rb'
5+
require '/opt/puppetlabs/puppet/cache/lib/pe_install/pe_postgresql_info.rb'
6+
7+
# Task which fetches the installed PSQL server major version
8+
class GetPSQLInfo < TaskHelper
9+
def task(**_kwargs)
10+
psql_info = PEPostgresqlInfo.new
11+
{ 'version' => psql_info.installed_server_version }
12+
end
13+
end
14+
15+
GetPSQLInfo.run if $PROGRAM_NAME == __FILE__

0 commit comments

Comments
 (0)