Exec: prefer "user => ..." rather than "command => 'sudo -u ..."

refs #6842
This commit is contained in:
Alexander Klimov 2014-09-10 17:49:17 +02:00
parent de4380e233
commit 413634280e
3 changed files with 9 additions and 6 deletions

View File

@ -22,10 +22,11 @@ define pgsql::database::create ($username, $password) {
include pgsql
exec { "create-pgsql-${name}-db":
unless => "sudo -u postgres 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}';\" && \
sudo -u postgres createdb -O ${username} -E UTF8 -T template0 ${name} && \
sudo -u postgres createlang plpgsql ${name}",
unless => "psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname='${username}'\" | grep -q 1",
command => "psql -c \"CREATE ROLE ${username} WITH LOGIN PASSWORD '${password}';\" && \
createdb -O ${username} -E UTF8 -T template0 ${name} && \
createlang plpgsql ${name}",
user => 'postgres',
require => Class['pgsql']
}
}

View File

@ -33,7 +33,8 @@ define pgsql::database::populate ($username, $password, $schemafile) {
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 *$'",
command => "sudo -u postgres psql -U ${username} -d ${name} < ${schemafile}",
command => "psql -U ${username} -d ${name} < ${schemafile}",
user => 'postgres',
require => [
Pgsql::Database::Create[$name],
Class['grep']

View File

@ -24,7 +24,8 @@ class icingaweb2_dev {
exec { 'populate-icingweb-pgsql-db-preferences':
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'],
}