title: Provisioning PostgreSQL with Puppet on Vagrant
body: <p>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.</p>
  
  <p>I'm trying to install Postgres using puppetlabs posgres module, creating a default role, and fixing up the DBs to work on UTF8.</p>
  
  <p>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.</p>
  
  <p>Here's the code I'm using on my manifest file.</p>
  
  <pre><code>user { "user_vagrant":
    ensure =&gt; "present",
  }-&gt;
  exec { 'apt_update':
    command =&gt; 'apt-get update',
    path    =&gt; '/usr/bin/'
  }
  
  package { ['vim','postgresql-server-dev-9.1','libmysqlclient-dev','nodejs']:
    ensure  =&gt; 'installed',
    before  =&gt; Class['postgresql::server'],
    require =&gt; Exec['apt_update'],
  }
  
  class { 'postgresql::server':
    ip_mask_allow_all_users =&gt; '0.0.0.0/0',
    listen_addresses        =&gt; '*',
    ipv4acls                =&gt; ['local all all md5'],
    postgres_password       =&gt; 'postgres',
    require                 =&gt; User['user_vagrant'],
  }
  
  postgresql::server::role { 'vagrant':
    createdb      =&gt; true,
    login         =&gt; true,
    password_hash =&gt; postgresql_password("vagrant", "vagrant"),
    require       =&gt; Class['postgresql::server'],
  } -&gt;
  exec { 'utf8_postgres':
    command =&gt; 'pg_dropcluster --stop 9.1 main ; pg_createcluster --start --locale en_US.UTF-8 9.1 main',
    unless =&gt; 'sudo -u postgres psql -t -c "\l" | grep template1 | grep -q UTF',
    path    =&gt; ['/bin', '/sbin', '/usr/bin', '/usr/sbin'],
  }
  </code></pre>