Exec: prefer "user => ..." rather than "command => 'sudo -u ..."
refs #6842
This commit is contained in:
parent
de4380e233
commit
413634280e
|
@ -22,10 +22,11 @@ define pgsql::database::create ($username, $password) {
|
||||||
include pgsql
|
include pgsql
|
||||||
|
|
||||||
exec { "create-pgsql-${name}-db":
|
exec { "create-pgsql-${name}-db":
|
||||||
unless => "sudo -u postgres psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname='${username}'\" | grep -q 1",
|
unless => "psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname='${username}'\" | grep -q 1",
|
||||||
command => "sudo -u postgres psql -c \"CREATE ROLE ${username} WITH LOGIN PASSWORD '${password}';\" && \
|
command => "psql -c \"CREATE ROLE ${username} WITH LOGIN PASSWORD '${password}';\" && \
|
||||||
sudo -u postgres createdb -O ${username} -E UTF8 -T template0 ${name} && \
|
createdb -O ${username} -E UTF8 -T template0 ${name} && \
|
||||||
sudo -u postgres createlang plpgsql ${name}",
|
createlang plpgsql ${name}",
|
||||||
|
user => 'postgres',
|
||||||
require => Class['pgsql']
|
require => Class['pgsql']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,8 @@ define pgsql::database::populate ($username, $password, $schemafile) {
|
||||||
|
|
||||||
exec { "populate-${name}-pgsql-db":
|
exec { "populate-${name}-pgsql-db":
|
||||||
onlyif => "psql -U ${username} -d ${name} -c \"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '${name}';\" 2>/dev/null |grep -qEe '^ *0 *$'",
|
onlyif => "psql -U ${username} -d ${name} -c \"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '${name}';\" 2>/dev/null |grep -qEe '^ *0 *$'",
|
||||||
command => "sudo -u postgres psql -U ${username} -d ${name} < ${schemafile}",
|
command => "psql -U ${username} -d ${name} < ${schemafile}",
|
||||||
|
user => 'postgres',
|
||||||
require => [
|
require => [
|
||||||
Pgsql::Database::Create[$name],
|
Pgsql::Database::Create[$name],
|
||||||
Class['grep']
|
Class['grep']
|
||||||
|
|
|
@ -24,7 +24,8 @@ class icingaweb2_dev {
|
||||||
|
|
||||||
exec { 'populate-icingweb-pgsql-db-preferences':
|
exec { 'populate-icingweb-pgsql-db-preferences':
|
||||||
unless => 'psql -U icingaweb -d icingaweb -c "SELECT * FROM preference;" &> /dev/null',
|
unless => 'psql -U icingaweb -d icingaweb -c "SELECT * FROM preference;" &> /dev/null',
|
||||||
command => 'sudo -u postgres psql -U icingaweb -d icingaweb -f /vagrant/etc/schema/preferences.pgsql.sql',
|
command => 'psql -U icingaweb -d icingaweb -f /vagrant/etc/schema/preferences.pgsql.sql',
|
||||||
|
user => 'postgres',
|
||||||
require => Pgsql::Database::Populate['icingaweb'],
|
require => Pgsql::Database::Populate['icingaweb'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue