Ask Your Question

puppetdb module not creating postgres db

asked 2015-05-19 16:01:18 -0600

Lori Cho gravatar image

updated 2015-05-20 16:08:16 -0600

Reworking my original post...

I'm trying to install puppetdb using the puppetlabs-puppetdb module which also installs postgresql and sets up the postgres db onto my puppetmaster host.

node /puppetmistress101/ inherits default {
        class { 'puppetdb':
        class { 'puppetdb::master::config':
It blows up when it tries to verify that the puppetdb has been created on the postgres server. At this point, I do not believe that the postgresql_psql types are being called. Error: echo 'Unable to connect to defined database using: /usr/bin/psql --tuples-only --quiet -h localhost -U puppetdb -p 5432 --dbname puppetdb ' && false returned 1 instead of one of [0]
When running puppet agent -t --debug, I see this: Debug: /Stage[main]/Puppetdb::Database::Postgresql/Postgresql::Server::Db[puppetdb]/Postgresql::Server::Database[puppetdb]/Postgresql_psql[Check for existence of db 'puppetdb']/notify: subscribes to Exec[/usr/bin/createdb --port='5432' --owner='postgres' --template=template0 'puppetdb'] I read that as it saying that the "check for existence" Exec won't run until after the Exec that creates the database. That would seem to make sense. Yet the puppetdb module code has this in modules/postgresql/manifests/server/database.pp
postgresql_psql { "Check for existence of db '${dbname}'":
    command => 'SELECT 1',
    unless  => "SELECT datname FROM pg_database WHERE datname='${dbname}'",
    db      => $default_db,
    port    => $port,
    require => Class['postgresql::server::service']
  exec { $createdb_command :
    refreshonly => true,
    user        => $user,
    logoutput   => true,
The puppet docs say:
~> (notification arrow) Causes the resource on the left to be applied first, and sends a refresh event to the resource on the right if the left resource changes. Written with a tilde and a greater-than sign.
Why does it seem like the debug output says the opposite of the code? I'm sure this is likely me misreading one of the two pieces.

There is no evidence in the debug output that the createdb command is being run. Only references to ordering.
root@puppetmistress101(puppet)# grep createdb /srv/tmp/debug | grep -i exec
Debug: /Stage[main]/Puppetdb::Database::Postgresql/Postgresql::Server::Db[puppetdb]/Postgresql::Server::Database[puppetdb]/Postgresql_psql[Check for existence of db 'puppetdb']/notify: subscribes to Exec[/usr/bin/createdb --port='5432' --owner='postgres' --template=template0  'puppetdb']
Debug: /Stage[main]/Puppetdb::Database::Postgresql/Postgresql::Server::Db[puppetdb]/Postgresql::Server::Database[puppetdb]/Exec[/usr/bin/createdb --port='5432' --owner='postgres' --template=template0  'puppetdb']/before: requires Postgresql_psql[UPDATE pg_database SET datistemplate = false WHERE datname = 'puppetdb']
Debug: /Stage[main]/Puppetdb::Database::Postgresql/Postgresql::Server::Db[puppetdb]/Postgresql::Server::Database[puppetdb]/Exec[/usr/bin/createdb --port='5432' --owner='postgres' --template=template0  'puppetdb']/notify: subscribes to Postgresql_psql[REVOKE ALL ON DATABASE "puppetdb" FROM public]
The requires for the postgresql service also seem satisfied:
root@puppetmistress101(puppet)# service postgresql status
postmaster (pid 27400 27399 27398 27396 27394) is running...

and that the verification that the service is running:

Debug: /Stage[main]/Postgresql::Server::Service/Postgresql::Validate_db_connection[validate_service_is_running]/Exec[validate postgres connection for @:5432/postgres]: Autorequiring File[/usr/local/bin/]
Debug: /Stage[main]/Postgresql::Server::Service/Postgresql::Validate_db_connection[validate_service_is_running]/Exec[validate postgres connection for @:5432/postgres]/unless: Try ...

edit retag flag offensive close merge delete


Please post a link to a pastebin of your code as well as the command you use to invoke the Puppet run.

GregLarkin gravatar imageGregLarkin ( 2015-05-19 17:57:07 -0600 )edit I run puppet with : puppet agent -t

Lori Cho gravatar imageLori Cho ( 2015-05-19 18:26:27 -0600 )edit

Can you also post the output to "puppet agent -t --debug"? Which ini file do you remove before running the agent?

GregLarkin gravatar imageGregLarkin ( 2015-05-19 18:54:06 -0600 )edit

I moved /etc/puppetdb/conf.d/database.ini to /etc/puppetdb/conf.d/database.ini2. I run puppet, and the file does not return. I captured debug output and am presenting everything related to puppetdb, postgresql, etc.

Lori Cho gravatar imageLori Cho ( 2015-05-19 23:15:29 -0600 )edit

Hmm, I'm stumped on this one. I can't tell why the database.ini file resources aren't making it into the catalog. Do you have any of the class variables defined in a Hiera data file that could cause the behavior of the module to change?

GregLarkin gravatar imageGregLarkin ( 2015-05-20 12:41:55 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-05-20 23:47:11 -0600

Lori Cho gravatar image

Thanks a bunch. I figured it out. We do not have our facts/plugins installed correctly on the puppetmaster.

We had our custom facts in /etc/puppet/plugins/facter, which is not quite proper, so when it looked for the other types/providers in the plugins directory, it wasn't finding them.

So I ran "puppet plugin download", and got the proper stuff in /var/lib/puppet/lib/puppet, then copied the /var/lib/puppet/lib/puppet dir into /etc/puppet/plugins/facter, and voila!! it all started working. (including my debug statements in the provider/postgresql_psql/ruby.rb file).

I find it really odd that there was literally no failure when trying to access types that it seemed to literally not have access to.

I appreciate all of your help. Thanks!

edit flag offensive delete link more


I'm not sure why Puppet behaved that way either, but I'm glad you got it working in the end. Make sure you have "pluginsync = true" in your puppet.conf file, and the Puppet agent should download plugins automatically in the future.

GregLarkin gravatar imageGregLarkin ( 2015-05-21 13:19:26 -0600 )edit

Actually, I had that. I also had: pluginsource = puppet:///oldplugins/

Lori Cho gravatar imageLori Cho ( 2015-05-21 13:42:59 -0600 )edit

answered 2015-05-20 19:32:59 -0600

GregLarkin gravatar image

I started with a CentOS 5.11 VM downloaded from Hashicorp Atlas and booted it with Vagrant. I wrote this Puppet manifest and applied it, and everything worked:

You'll notice some craziness in there to create some symlinks for things that were expected to be in certain places, and I didn't investigate the root cause, just fixed what was needed.

In the end, postgreSQL 8.4 was running with PuppetDB on top of it, and I was able to remove the .ini files and have them rebuilt on the next Puppet run.

I'm not sure this will be useful, but maybe some of it will point you in the right direction.

edit flag offensive delete link more


Would it be possible to see what your puppet agent -t output looked like? Is there any chance that something is misconfigured with my puppetmaster that it's talking to? (itself)

Lori Cho gravatar imageLori Cho ( 2015-05-20 21:56:16 -0600 )edit

Sure, check: There are 6 gists, but they're in a weird order. I ran the agent twice on a clean system, then I ran it 4 times after renaming database.ini. The titles of each gist on that page will tell which is which.

GregLarkin gravatar imageGregLarkin ( 2015-05-20 23:21:04 -0600 )edit

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: 2015-05-19 16:01:18 -0600

Seen: 705 times

Last updated: May 20 '15