Ask Your Question

how to create multiple postgresql databases via hiera

asked 2017-10-26 10:07:15 -0600

dtkloc gravatar image

I am using the Puppetlabs/postgresql module available on the forge and am able to create databases via the manifest file on my postgres server but cannot figure out how to do this via hiera. Can anyone help? running puppet 5.3 Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-11-06 12:45:52 -0600

eric aldinger gravatar image

updated 2017-11-06 12:54:00 -0600

Try a pattern lke this, where lookup is using Mongo or Consul backed hiera to manage secrets, and the password is encrypted (we use AWS and thier key management store, but the idea encrypt your password outside of Puppet and decrypt it with Puppet).

$db_names = [ $thisModule::params::db1, $thisModule::params::db2, $thisModule::params::db3, ]

$db_names.each |$db| { postgresql::server::db: "$db": user: lookup("${db}_user") password: kms_decrypt(lookup("${db}_password")) }

edit flag offensive delete link more

answered 2017-11-03 05:14:58 -0600

stivesso gravatar image

Hi dtkloc,

It's a bit tough to determine what you're trying to accomplish without code samples, but I'll take a stab and suggest that you use create_resources. See below an example:

The code:

class { 'postgresql::server':}

# Create a hash from Hiera Data with the Databases
$myPostgresDb = hiera('postgresql::server::db', {})

# With Create Resource Converts a hash into a set of resources
create_resources('postgresql::server::db', $myPostgresDb)

The Hiera Data:

    user:      'db1'
    password:  'db1'
    user:      'db2'
    password:  'db2'
    user:      'db3'
    password:  'db3'

Note that you can see a detailed example (with more explanation) of that approach here (used to define many vhosts on an Apache Servers).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2017-10-26 10:07:15 -0600

Seen: 406 times

Last updated: Nov 06 '17