how to ensure LVM created before installing postgres

271 views
Skip to first unread message

Alex Samad

unread,
Aug 15, 2016, 9:16:48 PM8/15/16
to Puppet Users
Hi

I would like to setup my LVM first 
PV
VG
PV 
mount that in /var/lib/pgsql/9.2/data and then use

# default
    class { 'postgresql::globals':
      manage_package_repo => false,
      version             => '9.2',
    }->
      class { 'postgresql::server':
      }


now for testing I haven't installed /dev/sdc which is my phys disk for the vg..

I would like the install of postgress to fail



    # predefined mounts
    # not done via lvm - can't do labels !

    # setup PG Data directory first
    file { '/var/lib/pgsql':
      ensure   => 'directory',
      group    => '26',
      mode     => '0700',
      owner    => '26',
    }

    file { '/var/lib/pgsql/9.2/':
      ensure   => 'directory',
      group    => '26',
      mode     => '0700',
      owner    => '26',
    }

    # incuded as part of the postgres module
#    file { '/var/lib/pgsql/9.2/data':
#      ensure   => 'directory',
#      group    => '26',
#      mode     => '0700',
#      owner    => '26',
#    }

    filesystem { '/dev/vg_pgdata/lv_pgdata':
      ensure => 'present',
      fs_type => 'ext4',
      options => '-L ybPGData',
    }

    mount { '/var/lib/pgsql/9.2/data':
      ensure  => 'mounted',
      device  => 'LABEL=ybPGData',
      dump    => '1',
      fstype  => 'ext4',
      options => 'defaults',
      pass    => '2',
      target  => '/etc/fstab',
    }

    volume_group { 'vg_pgdata':
      ensure => present,
      physical_volumes => '/dev/sdc1'
    }

    logical_volume { 'lv_pgdata':
      ensure => present,
      volume_group => 'vg_pgdata',
      size => '20G',
    }



    #
    # latest postgres rpm
    #
    package { 'pgdg-centos92-repo':
      name => 'pgdg-centos92',
      ensure => 'installed',
      provider => 'rpm',
      install_options => [
        '--httpproxy',
        'proxyyb',
        '--httpport',
        '3128',
      ]
    }

    # have to overwrite the repo file
    file { 're_pgdg-centos92':
      ensure => present,
      path => '/etc/yum.repos.d/pgdg-92-centos.repo',
      content => file('profile/ybpostgresql92/pgdg-92-centos.repo'),
      owner => 'root',
      group => 'root',
      mode => 'u=rw,g=r,o=r',
    }


    # default
    class { 'postgresql::globals':
      manage_package_repo => false,
      version             => '9.2',
    }->
      class { 'postgresql::server':
      }


Gavin Williams

unread,
Aug 16, 2016, 3:53:33 AM8/16/16
to Puppet Users
Alex


Basically, you can add "requires => Logical_Volume['lv_pgdata']" to the 'postgresql::server' class, and if the Logical_Volume resource fails for whatever reason, then the 'postgresql::server' class will be skipped... 

HTH

Gav

Alex Samad

unread,
Aug 16, 2016, 7:27:29 PM8/16/16
to Puppet Users
Okay

that sounds okay, how do I add fatal call to it to stop it processing any more 

Alex

Alex Samad

unread,
Aug 16, 2016, 7:44:42 PM8/16/16
to Puppet Users
Hi

Just tried this


    logical_volume { 'lv_pgdata92':
      ensure => present,
      volume_group => 'vg_pgdata',

      requires => volume_group { 'vg_pgdata':
          ensure => present,
          physical_volumes => '/dev/sdc1'
        }

Got this 
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Syntax error at '{' at /etc/puppetlabs/code/environments/testing/site/profile/manifests/ybpostgresql92.pp:51:32 on node bitbucket.yieldbroker.com
W

Alex Samad

unread,
Aug 16, 2016, 7:55:42 PM8/16/16
to Puppet Users
HI

So got this to work 

    volume_group { 'vg_pgdata':
      ensure => present,
      physical_volumes => '/dev/sdc1'
    }

    logical_volume { 'lv_pgdata92':
      ensure => present,
      volume_group => 'vg_pgdata',

      require => Volume_Group['vg_pgdata'],

    }


Also found out that I can't have spaces between File and [

so 
File[ is difference from File [

Not sure I fully understand the <resource>[] and the difference between <resource>{ '':}

A


On Wednesday, 17 August 2016 09:44:42 UTC+10, Alex Samad wrote:
Hi

Just tried this


    logical_volume { 'lv_pgdata92':
      ensure => present,
      volume_group => 'vg_pgdata',

      requires => volume_group { 'vg_pgdata':
          ensure => present,
          physical_volumes => '/dev/sdc1'
        }

Got this 
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Syntax error at '{' at /etc/puppetlabs/code/environments/testing/site/profile/manifests/ybpostgresql92.pp:51:32 on node bitbucket.yieldbroker.com
W


On Wednesday, 17 August 2016 09:27:29 UTC+10, Alex Samad wrote:
Okay

that sounds okay, how do I add fatal call to it to stop it processing any more 

Alex

On Tuesday, 16 August 2016 17:53:33 UTC+10, Gavin Williams wrote:
Alex


Basically, you can add "requires => Logical_Volume['lv_pgdata']" to the 'postgresql::server' class, and if the Logical_Volume resource fails for whatever reason, then the 'postgresql::server' class will be skipped... 

HTH

Gav
[snip]

Gavin Williams

unread,
Aug 17, 2016, 2:48:52 AM8/17/16
to Puppet Users
Alex


With regards to erroring, you don't need to do anything special, other than setup the relationship using 'before/requires' between the Logical_Volume resource and the Postgresql class. 

If the Logical_Volume resource fails to apply, then Puppet will skip the Postgresql class. 

Also, you don't need to explicitly order the LVM PV<>VG<>LV resources, as they already setup the requires dependencies in the resource providers - See https://docs.puppet.com/puppet/latest/reference/lang_relationships.html#auto-relationships

HTH

Gav

Alex Samad

unread,
Aug 18, 2016, 12:09:10 AM8/18/16
to Puppet Users
Hi


  # setup postgres
  postgresql::server::db { 'bitbucket':
    user     => $butbucketuser,
    password => postgresql_password( $butbucketuser , $bitbucketpass ),
  }




  class { 'bitbucket':
    # fix to version 8
    javahome    => '/usr/java/java8',
    version        => '4.8.3',
    installdir     => '/apps/atlassian/atlassian-bitbucket',
    homedir        => '/apps/atlassian/application-data/bitbucket-home',
    uid => 525,
    gid => 525,
    dbpassword     => $bitbucketpass,
    service_manage => false,
    jvm_xms        => '1G',
    jvm_xmx        => '4G',
    proxy          => {
      scheme       => 'https',
      proxyName    => 'bitbucket.yieldbroker.com',
      proxyPort    => '443',
    },
    tomcat_port    => '7991'

    require => postgresql::server::db['bitbucket'],


this seems to fail, how do I make the DB a require for bitbucket install ?

A
Reply all
Reply to author
Forward
0 new messages