Puppet Class: rancher::server

Inherits:
::rancher::params
Defined in:
manifests/server.pp

Overview

Parameters:

  • ensure (Any) (defaults to: 'present')
  • port (Any) (defaults to: $::rancher::params::server_port)
  • image_tag (Any) (defaults to: $::rancher::params::image_tag)
  • container_name (Any) (defaults to: $::rancher::params::container_name)
  • db_port (Any) (defaults to: $::rancher::params::db_port)
  • db_name (Any) (defaults to: $::rancher::params::db_name)
  • db_user (Any) (defaults to: $::rancher::params::db_user)
  • db_password (Any) (defaults to: $::rancher::params::db_password)
  • db_container (Any) (defaults to: $::rancher::params::db_container)
  • dns (Any) (defaults to: $::rancher::params::dns)
  • dns_search (Any) (defaults to: $::rancher::params::dns_search)


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
114
115
116
117
118
119
120
121
# File 'manifests/server.pp', line 49

class rancher::server(
  $ensure = 'present',
  $port = $::rancher::params::server_port,
  $image_tag = $::rancher::params::image_tag,
  $container_name = $::rancher::params::container_name,
  $db_port = $::rancher::params::db_port,
  $db_name = $::rancher::params::db_name,
  $db_user = $::rancher::params::db_user,
  $db_password = $::rancher::params::db_password,
  $db_container = $::rancher::params::db_container,
  $dns = $::rancher::params::dns,
  $dns_search = $::rancher::params::dns_search,
) inherits ::rancher::params {

  validate_re($ensure, '^(present|absent)', 'ensure should be present or absent')
  validate_integer($port)
  validate_string($container_name)
  validate_array($dns)
  validate_array($dns_search)
  
  if  ($db_port != undef) and
      ($db_name != undef) and
      ($db_user != undef) and
      ($db_password != undef) and
      ($db_container != undef) {
    validate_string($db_container)
    validate_string($db_name)
    validate_string($db_user)
    validate_string($db_password)
    validate_integer($db_port)
    $env = [
      "CATTLE_DB_CATTLE_MYSQL_HOST=${db_container}",
      "CATTLE_DB_CATTLE_MYSQL_PORT=${db_port}",
      "CATTLE_DB_CATTLE_MYSQL_NAME=${db_name}",
      "CATTLE_DB_CATTLE_USERNAME=${db_user}",
      "CATTLE_DB_CATTLE_PASSWORD=${db_password}",
    ]
    $links = [ $db_container ]
    $depends = [ $db_container ]
    docker::image {'mariadb':
      image_tag => 'latest',
    } ->
    docker::run { $db_container:
      image   => 'mariadb',
      env     => [
        "MYSQL_ROOT_PASSWORD=${db_password}",
        "MYSQL_USER=${db_user}",
        "MYSQL_PASSWORD=${db_password}",
        "MYSQL_DATABASE=${db_name}",
      ],
      volumes => [ "/var/lib/${db_container}:/var/lib/mysql" ],
      notify  => Docker::Run[$container_name],
    }
  } else {
    $env = []
    $links = []
    $depends = []
  }

  docker::image { 'rancher/server':
    image_tag => $image_tag,
  } ->
  docker::run { $container_name:
    ensure     => $ensure,
    image      => 'rancher/server',
    ports      => ["${port}:8080"],
    env        => $env,
    links      => $links,
    depends    => $depends,
    dns        => $dns,
    dns_search => $dns_search,
  }
}