Question

I've got a puppet manifest that resists my attempts to get it working right, given I'm no expert on the puppet DSL, and I'm fairly new to Puppet, I haven't managed to figure this out.

I'm trying to install Postgres using puppetlabs posgres module, creating a default role, and fixing up the DBs to work on UTF8.

Everything runs and installs, but the role doesn't get created. But if I run the provision again, then the role gets created. I assume perhaps has to do with the execution order, but honestly I'm lost.

Here's the code I'm using on my manifest file.

user { "user_vagrant":
  ensure => "present",
}->
exec { 'apt_update':
  command => 'apt-get update',
  path    => '/usr/bin/'
}

package { ['vim','postgresql-server-dev-9.1','libmysqlclient-dev','nodejs']:
  ensure  => 'installed',
  before  => Class['postgresql::server'],
  require => Exec['apt_update'],
}

class { 'postgresql::server':
  ip_mask_allow_all_users => '0.0.0.0/0',
  listen_addresses        => '*',
  ipv4acls                => ['local all all md5'],
  postgres_password       => 'postgres',
  require                 => User['user_vagrant'],
}

postgresql::server::role { 'vagrant':
  createdb      => true,
  login         => true,
  password_hash => postgresql_password("vagrant", "vagrant"),
  require       => Class['postgresql::server'],
} ->
exec { 'utf8_postgres':
  command => 'pg_dropcluster --stop 9.1 main ; pg_createcluster --start --locale en_US.UTF-8 9.1 main',
  unless => 'sudo -u postgres psql -t -c "\l" | grep template1 | grep -q UTF',
  path    => ['/bin', '/sbin', '/usr/bin', '/usr/sbin'],
}
Was it helpful?

Solution

Finally found the right approach to fix both the applied order, and the UTF8 issue which forced me to try the "pg_dropcluster" to begin with. Btw, this is a known issue here's the issue url http://projects.puppetlabs.com/issues/4695

This is the whole file I use to install PostgreSQL 9.1 with UTF8, and RVM ruby. Hope this helps.

Modules:
- puppetlabs/apt - 1.4
- puppetlabs/concat - 1.0
- puppetlabs/stdlib - 4.1.0
- puppetlabs/postgresql - 3.2
- blt04/puppet-rvm - git://github.com/blt04/puppet-rvm.git

stage { 'pre':
  before => Stage['main']
}

class pre_req {
  user { "vagrant":
    ensure => "present",
  }

  exec { 'apt-update':
    command => 'apt-get update',
    path    => '/usr/bin'
  }->
  exec { 'install_postgres':
    command => "/bin/bash -c 'LC_ALL=en_US.UTF-8; /usr/bin/apt-get -y install postgresql'",
  }
}

class { 'pre_req':
  stage => pre
}

package { ['postgresql-server-dev-9.1']:
  ensure  => 'installed',
  before  => Class['postgresql::server']
}

class { 'postgresql::globals':
  encoding => 'UTF8',
  locale   => 'en_US.UTF-8'
}->
class { 'postgresql::server':
  stage                   => main,
  locale                  => 'en_US.UTF-8',
  ip_mask_allow_all_users => '0.0.0.0/0',
  listen_addresses        => '*',
  ipv4acls                => ['local all all md5'],
  postgres_password       => 'postgres',
  require                 => User['vagrant']
}->
postgresql::server::role { 'vagrant':
  createdb      => true,
  login         => true,
  password_hash => postgresql_password("vagrant", "vagrant"),
}

class rvm_install {
  class { 'rvm': version => '1.23.10' }
  rvm::system_user { vagrant: ; }
  rvm_system_ruby {
    "ruby-2.0.0-p247":
    ensure      => "present",
    default_use => false;
  }
  rvm_gemset {
    "ruby-2.0.0-p247@plyze":
    ensure  => present,
    require => Rvm_system_ruby['ruby-2.0.0-p247'];
  }
  rvm_gem {
    "puppet":
    name         => "puppet",
    ruby_version => "ruby-2.0.0-p247",
    ensure       => latest,
    require      => Rvm_system_ruby["ruby-2.0.0-p247"];
  }
  rvm_gem {
    "bundler":
    name         => "bundler",
    ruby_version => "ruby-2.0.0-p247",
    ensure       => latest,
    require      => Rvm_system_ruby["ruby-2.0.0-p247"];
  }
}

class { 'rvm_install':
  require => User['vagrant'],
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top