module-puppetdb/manifests/server/database_ini.pp

135 lines
4.3 KiB
ObjectPascal
Raw Normal View History

# Class: puppetdb::server::database_ini
#
# This class manages puppetdb's `database.ini` file.
#
# Parameters:
# ['database'] - Which database backend to use; legal values are
# `postgres` (default) or `embedded`. (The `embedded`
# db can be used for very small installations or for
# testing, but is not recommended for use in production
# environments. For more info, see the puppetdb docs.)
# ['database_host'] - The hostname or IP address of the database server.
# (defaults to `localhost`; ignored for `embedded` db)
# ['database_port'] - The port that the database server listens on.
# (defaults to `5432`; ignored for `embedded` db)
# ['database_user'] - The name of the database user to connect as.
# (defaults to `puppetdb`; ignored for `embedded` db)
# ['database_password'] - The password for the database user.
# (defaults to `puppetdb`; ignored for `embedded` db)
# ['database_name'] - The name of the database instance to connect to.
# (defaults to `puppetdb`; ignored for `embedded` db)
# ['confdir'] - The puppetdb configuration directory; defaults to
# `/etc/puppetdb/conf.d`.
#
# Actions:
# - Manages puppetdb's `database.ini` file
#
# Requires:
# - Inifile
#
# Sample Usage:
# class { 'puppetdb::server::database_ini':
2012-09-20 23:46:26 +02:00
# database_host => 'my.postgres.host',
# database_port => '5432',
# database_username => 'puppetdb_pguser',
# database_password => 'puppetdb_pgpasswd',
# database_name => 'puppetdb',
# }
#
class puppetdb::server::database_ini(
2012-09-20 23:46:26 +02:00
$database = $puppetdb::params::database,
$database_host = $puppetdb::params::database_host,
$database_port = $puppetdb::params::database_port,
$database_username = $puppetdb::params::database_username,
$database_password = $puppetdb::params::database_password,
$database_name = $puppetdb::params::database_name,
$node_ttl = $puppetdb::params::node_ttl,
$node_purge_ttl = $puppetdb::params::node_purge_ttl,
$report_ttl = $puppetdb::params::report_ttl,
2012-09-20 23:46:26 +02:00
$confdir = $puppetdb::params::confdir,
) inherits puppetdb::params {
# Validate the database connection. If we can't connect, we want to fail
# and skip the rest of the configuration, so that we don't leave puppetdb
# in a broken state.
class { 'puppetdb::server::validate_db':
2012-09-20 23:46:26 +02:00
database => $database,
database_host => $database_host,
database_port => $database_port,
database_username => $database_username,
database_password => $database_password,
database_name => $database_name,
}
#Set the defaults
Ini_setting {
2012-09-20 23:46:26 +02:00
path => "${confdir}/database.ini",
ensure => present,
section => 'database',
require => Class['puppetdb::server::validate_db'],
}
2012-09-20 23:46:26 +02:00
if $database == 'embedded'{
2012-09-20 23:46:26 +02:00
$classname = 'org.hsqldb.jdbcDriver'
$subprotocol = 'hsqldb'
$subname = $puppetdb::params::embedded_subname
2012-09-20 23:46:26 +02:00
} elsif $database == 'postgres' {
$classname = 'org.postgresql.Driver'
$subprotocol = 'postgresql'
$subname = "//${database_host}:${database_port}/${database_name}"
2012-09-20 23:46:26 +02:00
##Only setup for postgres
ini_setting {'puppetdb_psdatabase_username':
setting => 'username',
value => $database_username,
}
ini_setting {'puppetdb_psdatabase_password':
setting => 'password',
value => $database_password,
}
}
ini_setting {'puppetdb_classname':
2012-09-20 23:46:26 +02:00
setting => 'classname',
value => $classname,
}
2012-09-20 23:46:26 +02:00
ini_setting {'puppetdb_subprotocol':
2012-09-20 23:46:26 +02:00
setting => 'subprotocol',
value => $subprotocol,
}
2012-09-20 23:46:26 +02:00
ini_setting {'puppetdb_pgs':
2012-09-20 23:46:26 +02:00
setting => 'syntax_pgs',
value => true,
}
2012-09-20 23:46:26 +02:00
ini_setting {'puppetdb_subname':
2012-09-20 23:46:26 +02:00
setting => 'subname',
value => $subname,
}
2012-09-20 23:46:26 +02:00
ini_setting {'puppetdb_gc_interval':
2012-09-20 23:46:26 +02:00
setting => 'gc-interval',
value => $puppetdb::params::gc_interval,
}
ini_setting {'puppetdb_node_ttl':
setting => 'node-ttl',
value => $node_ttl,
}
ini_setting {'puppetdb_node_purge_ttl':
setting => 'node-purge-ttl',
value => $node_purge_ttl,
}
ini_setting {'puppetdb_report_ttl':
setting => 'report-ttl',
value => $report_ttl,
}
}