Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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 (
  $some_param_in_hiera,
  ){

  package {
    'foo_pkg':
      ensure => installed,
  }

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

  file {
    '/etc/foo/some.conf':
      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 {
    'some_task':
      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: pgcon.org/2013/schedule/events/540.en.html –  Peter Eisentraut May 31 '13 at 13:13

Your Answer

 
discard

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.