Skip to content
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

Don't assume db_host will be localhost in postgresql.pp #20

Merged
merged 3 commits into from
Dec 6, 2014
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
3 changes: 2 additions & 1 deletion manifests/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
db_name => $db_name,
db_user => $db_user,
db_pass => $db_pass,
db_host => $db_host,
}
}
'mysql': {
Expand All @@ -54,4 +55,4 @@
}
} # END case $dbtype
}
}
}
25 changes: 14 additions & 11 deletions manifests/database/postgresql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$db_name = '',
$db_user = '',
$db_pass = '',
$db_host = '',
) {

case $::operatingsystem {
Expand All @@ -34,16 +35,19 @@
}
}

# Creating database
postgresql::server::db { $db_name:
user => $db_user,
password => postgresql_password($db_user, $db_pass),
# If the database is meant to be on the same node as zabbix, then create it now.
if ($db_host == 'localhost') {
class { 'zabbix::database::remotepostgresql':
dbname => $db_name,
dbuser => $db_user,
dbpassword => $db_pass,
}
}

exec { 'update_pgpass':
command => "echo localhost:5432:${db_name}:${db_user}:${db_pass} >> ${postgres_home}/.pgpass",
command => "echo ${db_host}:5432:${db_name}:${db_user}:${db_pass} >> ${postgres_home}/.pgpass",
path => '/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
unless => "grep \"localhost:5432:${db_name}:${db_user}:${db_pass}\" ${postgres_home}/.pgpass",
unless => "grep \"${db_host}:5432:${db_name}:${db_user}:${db_pass}\" ${postgres_home}/.pgpass",
require => File["${postgres_home}/.pgpass"],
}

Expand All @@ -52,13 +56,12 @@
mode => '0600',
owner => 'postgres',
group => 'postgres',
require => Postgresql::Server::Db[$db_name],
}

case $zabbix_type {
'proxy': {
exec { 'zabbix_proxy_create.sql':
command => "cd ${zabbix_path} && sudo -u postgres psql -h localhost -U ${db_user} -d ${db_name} -f schema.sql && touch schema.done",
command => "cd ${zabbix_path} && sudo -u postgres psql -h ${db_host} -U ${db_user} -d ${db_name} -f schema.sql && touch schema.done",
path => '/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
unless => "test -f ${zabbix_path}/schema.done",
provider => 'shell',
Expand All @@ -71,7 +74,7 @@
}
'server': {
exec { 'zabbix_server_create.sql':
command => "cd ${zabbix_path} && sudo -u postgres psql -h localhost -U ${db_user} -d ${db_name} -f schema.sql && touch schema.done",
command => "cd ${zabbix_path} && sudo -u postgres psql -h ${db_host} -U ${db_user} -d ${db_name} -f schema.sql && touch schema.done",
path => '/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
unless => "test -f ${zabbix_path}/schema.done",
provider => 'shell',
Expand All @@ -82,7 +85,7 @@
notify => Service['zabbix-server'],
} ->
exec { 'zabbix_server_images.sql':
command => "cd ${zabbix_path} && sudo -u postgres psql -h localhost -U ${db_user} -d ${db_name} -f images.sql && touch images.done",
command => "cd ${zabbix_path} && sudo -u postgres psql -h ${db_host} -U ${db_user} -d ${db_name} -f images.sql && touch images.done",
path => '/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
unless => "test -f ${zabbix_path}/images.done",
provider => 'shell',
Expand All @@ -93,7 +96,7 @@
notify => Service['zabbix-server'],
} ->
exec { 'zabbix_server_data.sql':
command => "cd ${zabbix_path} && sudo -u postgres psql -h localhost -U ${db_user} -d ${db_name} -f data.sql && touch data.done",
command => "cd ${zabbix_path} && sudo -u postgres psql -h ${db_host} -U ${db_user} -d ${db_name} -f data.sql && touch data.done",
path => '/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
unless => "test -f ${zabbix_path}/data.done",
provider => 'shell',
Expand Down
11 changes: 11 additions & 0 deletions manifests/database/remotepostgresql.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class zabbix::database::remotepostgresql (
$dbname = $zabbix::params::server_dbname,
$dbuser = $zabbix::params::server_dbuser,
$dbpassword = $zabbix::params::server_dbpassword,
) inherits zabbix::params {

postgresql::server::db { $dbname:
user => $dbuser,
password => postgresql_password($dbuser, $dbpassword),
}
}