Puppet Class: openshift_origin::datastore

Defined in:
manifests/datastore.pp

Overview

Copyright 2013 Mojo Lingo LLC. Modifications by Red Hat, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'manifests/datastore.pp', line 16

class openshift_origin::datastore {
  anchor { 'openshift_origin::datastore_begin': } ->
  class { 'openshift_origin::firewall::mongodb': } ->
  anchor { 'openshift_origin::datastore_end': }

  package { ['mongodb', 'mongodb-server', 'rubygem-open4']:
    ensure  => present,
    require => Class['openshift_origin::install_method'],
  }

  # TODO: See about replacing with Mongo Puppet module

  $port = $openshift_origin::mongodb_port

  file { 'mongo setup script':
    ensure  => present,
    path    => '/usr/sbin/oo-mongo-setup',
    content => template('openshift_origin/mongodb/oo-mongo-setup'),
    owner   => 'root',
    group   => 'root',
    mode    => '0700',
    require => [
      Package['mongodb'],
      Package['mongodb-server'],
      Package['rubygem-open4'],
    ],
  }

  exec { '/usr/sbin/oo-mongo-setup':
    command => '/usr/sbin/oo-mongo-setup',
    timeout => 1800,
    require => [
      File['mongo setup script'],
      Class['openshift_origin::update_conf_files'],
    ],
    creates => '/etc/openshift/.mongo-setup-complete',
  }

  if $openshift_origin::mongodb_replicasets {
    file { $openshift_origin::mongodb_keyfile:
      content => inline_template($openshift_origin::mongodb_key),
      owner   => 'mongodb',
      group   => 'mongodb',
      mode    => '0400',
      require => Exec['/usr/sbin/oo-mongo-setup'],
      notify  => Service['mongod'],
    }
    exec { 'keyfile-mongo-conf':
      path    => ['/bin/', '/usr/bin/', '/usr/sbin/'],
      command => "echo -e \"\nkeyFile = ${openshift_origin::mongodb_keyfile}\n\" >> /etc/mongodb.conf",
      unless  => "grep \"keyFile = ${openshift_origin::mongodb_keyfile}\" /etc/mongodb.conf",
      require => File[$openshift_origin::mongodb_keyfile],
      notify  => Service['mongod'],
    }
    exec { 'replset-mongo-conf':
      path    => ['/bin/', '/usr/bin/', '/usr/sbin/'],
      command => "echo -e \"\nreplSet = ${openshift_origin::mongodb_replica_name}\n\" >> /etc/mongodb.conf",
      unless  => "grep \"replSet = ${openshift_origin::mongodb_replica_name}\" /etc/mongodb.conf",
      require => [
        File[$openshift_origin::mongodb_keyfile],
        Exec['/usr/sbin/oo-mongo-setup']
      ],
      notify  => Service['mongod'],
    }
    if $openshift_origin::mongodb_replica_primary {
      exec { 'replset-init':
        path      => ['/bin/', '/usr/bin/', '/usr/sbin/'],
        command   => "mongo admin -u ${openshift_origin::mongodb_admin_user} -p ${openshift_origin::mongodb_admin_password} --quiet --eval printjson\"(rs.initiate({ _id: \'${openshift_origin::mongodb_replica_name}\', members: [ { _id: 0, host: \'${::ipaddress}:${port}\' } ] }))\"",
        unless    => "mongo admin --host ${::ipaddress} -u ${openshift_origin::mongodb_admin_user} -p ${openshift_origin::mongodb_admin_password} --quiet --eval \"printjson(rs.status())\" | grep '\"name\" : \"${::ipaddress}:${port}\"'",
        tries     => 3,
        try_sleep => 5,
        require   => [
          Service['mongod'],
          Exec['keyfile-mongo-conf', 'replset-mongo-conf']
        ],
      }
    }
    elsif $openshift_origin::parallel_deployment == false {
      # Only run the replset-add command if we are not in the middle of instantiating multiple hosts at once.
      exec { 'replset-add':
        path      => ['/bin/', '/usr/bin/', '/usr/sbin/'],
        command   => "mongo admin --host ${openshift_origin::mongodb_replica_primary_ip_addr} -u ${openshift_origin::mongodb_admin_user} -p ${openshift_origin::mongodb_admin_password} --quiet --eval \"printjson(rs.add(\'${::ipaddress}:${port}\'))\"",
        unless    => "mongo admin --host ${openshift_origin::mongodb_replica_primary_ip_addr} -u ${openshift_origin::mongodb_admin_user} -p ${openshift_origin::mongodb_admin_password} --quiet --eval \"printjson(rs.status())\" | grep '\"name\" : \"${::ipaddress}:${port}\"'",
        tries     => 6,
        try_sleep => 30,
        require   => [
          Service['mongod'],
          Exec['keyfile-mongo-conf', 'replset-mongo-conf']
        ],
      }
    }
  }

  service { 'mongod':
    require => [Package['mongodb'], Package['mongodb-server']],
    enable  => true,
  }
}