Skip to content

unique resource titles to allow multiple instances #1503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions manifests/server/instance/initdb.pp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@

# This runs the initdb command, we use the existance of the PG_VERSION
# file to ensure we don't keep running this command.
exec { 'postgresql_initdb':
exec { "postgresql_initdb_instance_${name}":
command => $initdb_command,
creates => "${datadir}/PG_VERSION",
user => $user,
Expand All @@ -185,6 +185,11 @@
cwd => $module_workdir,
}
} elsif $encoding != undef {
include postgresql::server::late_initdb
postgresql::server::instance::late_initdb { $name:
encoding => $encoding,
user => $user,
group => $group,
module_workdir => $module_workdir,
}
}
}
2 changes: 1 addition & 1 deletion manifests/server/instance/passwd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# the default for pg_hba.conf.
$escaped = postgresql::postgresql_escape($real_postgres_password)
$exec_command = "${stdlib::shell_escape($psql_path)}${_dboption} -c \"ALTER ROLE \\\"${stdlib::shell_escape($user)}\\\" PASSWORD \${NEWPASSWD_ESCAPED}\"" # lint:ignore:140chars
exec { 'set_postgres_postgrespw':
exec { "set_postgres_postgrespw_${name}":
# This command works w/no password because we run it as postgres system
# user
command => $exec_command,
Expand Down
2 changes: 1 addition & 1 deletion manifests/server/instance/reload.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
String[1] $service_status = $postgresql::server::service_status,
String[1] $service_reload = $postgresql::server::service_reload,
) {
exec { 'postgresql_reload':
exec { "postgresql_reload_${name}":
path => '/usr/bin:/usr/sbin:/bin:/sbin',
command => $service_reload,
onlyif => $service_status,
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/server/initdb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class { 'postgresql::server': }
end

it 'contains exec with specified working directory' do
expect(subject).to contain_exec('postgresql_initdb').with(
expect(subject).to contain_exec('postgresql_initdb_instance_main').with(
cwd: '/var/tmp',
)
end
Expand All @@ -82,7 +82,7 @@ class { 'postgresql::server': }
end

it 'contains exec with default working directory' do
expect(subject).to contain_exec('postgresql_initdb').with(
expect(subject).to contain_exec('postgresql_initdb_instance_main').with(
cwd: '/tmp',
)
end
Expand Down
22 changes: 11 additions & 11 deletions spec/classes/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
it { is_expected.to contain_file('/var/lib/postgresql/13/main') }

it {
expect(subject).to contain_exec('postgresql_reload').with('command' => 'systemctl reload postgresql')
expect(subject).to contain_exec('postgresql_reload_main').with('command' => 'systemctl reload postgresql')
}

it 'validates connection' do
Expand Down Expand Up @@ -65,10 +65,10 @@ class { 'postgresql::globals':
end

it 'sets postgres password' do
expect(subject).to contain_exec('set_postgres_postgrespw').with('command' => '/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"',
'user' => 'postgres',
'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'],
'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null")
expect(subject).to contain_exec('set_postgres_postgrespw_main').with('command' => '/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"',
'user' => 'postgres',
'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'],
'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null")
end
end

Expand All @@ -89,10 +89,10 @@ class { 'postgresql::globals':
end

it 'sets postgres password' do
expect(subject).to contain_exec('set_postgres_postgrespw').with('command' => ['/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"'],
'user' => 'postgres',
'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'],
'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null")
expect(subject).to contain_exec('set_postgres_postgrespw_main').with('command' => ['/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"'],
'user' => 'postgres',
'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'],
'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null")
end
end

Expand Down Expand Up @@ -146,7 +146,7 @@ class { 'postgresql::globals':
it { is_expected.to contain_class('postgresql::server') }

it {
expect(subject).to contain_exec('postgresql_reload').with('command' => '/bin/true')
expect(subject).to contain_exec('postgresql_reload_main').with('command' => '/bin/true')
}

it 'validates connection' do
Expand Down Expand Up @@ -194,7 +194,7 @@ class { 'postgresql::globals':
end

it 'contains proper initdb exec' do
expect(subject).to contain_exec('postgresql_initdb')
expect(subject).to contain_exec('postgresql_initdb_instance_main')
end
end

Expand Down