Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We are trying to write a Puppet to provision the Virtual Machine. One of the tasks is to install and populate Postgres database with data.

We can decompose this task into a few smaller tasks:

  1. install
  2. initdb
  3. start
  4. populate database with data (pg_dump from production database)

It seems Puppet will be responsible for Step 1: install.

Should we use Puppet to perform Step 2, 3, 4 as well?

share|improve this question
up vote 2 down vote accepted

A common pattern when using puppet is managing the installation, configuration and service status of a package. You last step can also be achieved as long as you ensure idempotency. A (very) simple skeleton for this kind of task:

class foo (

  package {
      ensure => installed,

  service {
      ensure    => running,
      enable    => true,
      hasstatus => true,
      require   => Package['foo_pkg'];

  file {
      mode    => '0644',
      owner   => root,
      group   => root,
      source  => 'puppet:///modules/foo/some.conf',
      #content => template('foo/some.conf.erb'),
      require => Package['foo_pkg'],
      notify  => Service['foo_svc'];

  exec {
      command     => 'echo 'foo bar baz'',
      refreshonly => true,
      creates     => '/some/file/to/ensure/idempotency'

Also, check the Puppet Forge for already existing code that does what you want.

share|improve this answer

The first three steps are definitely within Puppet's realm. Installation is a package resource, initdb can be done with exec if the package doesn't do it itself, and starting the service is a service resource.

But populating the database is probably not a good use of Puppet. You could probably do it with a lot of custom code (e.g, a separate resource type for a table, a function, etc.), but it would be a lot of work and somewhat unchartered territory. I suggest you look for a different way to do that.

share|improve this answer
Some reading on this: – Peter Eisentraut May 31 '13 at 13:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.