Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare all resources as external #8

Merged
merged 2 commits into from
Mar 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# == Class: webapp
#
class webapp(
$creation_mode = 'local',
$instance_defaults = {},
) {

$instances = hiera_hash('webapp::instances', {})

$creation_modes = [ 'local', 'exported' ]
if ! ($creation_mode in $creation_modes) {
fail("'${creation_mode}' is not a valid value for creation_mode. Valid values: ${creation_modes}.")
}

create_resources('::webapp::instance', $instances, $instance_defaults)

require webapp::autorealize
Expand Down
81 changes: 20 additions & 61 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
#
# === Parameters
#
# [*creation_mode*]
# Resources creation mode. Specify whether the resources will be created
# locally for this node or instead they're created as exported resources.
# Valid values: local, exported.
# Default: local.
#
# [*type*]
# Type of web application. Any value is supported. We only recognize: drupal.
# In case of drupal, this indicates a drush alias will be declared.
Expand Down Expand Up @@ -160,7 +154,6 @@
# See init.pp for details.
#
define webapp::instance(
$creation_mode = $webapp::creation_mode,
$type = undef,
# Apache
$vhost_ensure = present,
Expand Down Expand Up @@ -202,21 +195,9 @@
$solr_version = undef,
$solr_initialize = false,

$tags = [],
$tags = [$::fqdn],
) {

case $creation_mode {
'local': {
$prefix = ''
}
'exported': {
$prefix = '@@'
}
default: {
fail("'${creation_mode}' is not a valid value for creation_mode. Valid values: local, exported.")
}
}

$ensure_options = [ present, absent ]

################################################################[ Web Head ]###
Expand Down Expand Up @@ -244,14 +225,10 @@
absent => absent,
present => directory,
}
$file_docroot_name = "${docroot_prefix}/${real_docroot_folder}"
$file_docroot_params = {
@@file { "${docroot_prefix}/${real_docroot_folder}":
ensure => $ensure_docroot_parent,
tag => $tags,
}
if !defined(File[$file_docroot_name]) {
create_resources("${prefix}file", { "${file_docroot_name}" => $file_docroot_params } )
}

# Redirect example.com to www.example.com or the inverse, or nothing at all.
case $www_ensure {
Expand All @@ -271,7 +248,7 @@
}
}
if $www_ensure != undef {
$apache_vhost_redirector_params = {
@@apache::vhost { $servername_source:
ensure => $vhost_ensure,
servername => $servername_source,
ip => $ip,
Expand All @@ -286,14 +263,11 @@
error_log => $logs_enable,
tag => $tags,
}
if !defined(Apache::Vhost[$servername_source]) {
create_resources("${prefix}apache::vhost", { $servername_source => $apache_vhost_redirector_params })
}
}

$redirects_fragment = template('webapp/apache/redirects.erb')
$custom_fragment = "${redirects_fragment}\n${vhost_extra}"
$apache_vhost_params = merge($vhost_extra_params, {
@@apache::vhost { $servername_real:
ensure => $vhost_ensure,
servername => $servername_real,
serveraliases => $serveraliases,
Expand All @@ -308,43 +282,36 @@
access_log => $logs_enable,
error_log => $logs_enable,
tag => $tags,
})
if !defined(Apache::Vhost[$servername_real]) {
create_resources("${prefix}apache::vhost", { $servername_real => $apache_vhost_params })
* => $vhost_extra_params,
}

if ($type == 'drupal') {
$drush_alias = {
@@drush::alias { $name:
ensure => $vhost_ensure,
uri => $servername_real,
root => $docroot,
tag => $tags,
}
if !defined(Drush::Alias[$name]) {
create_resources("${prefix}drush::alias", { "${name}" => $drush_alias } )
}
}

if !($hosts_ensure in [undef, '']) {
# Merge hosts and filter those with an *.
$hosts = flatten([$servername, $serveraliases])
$real_hosts = difference($hosts, grep($hosts, '\*'))
$real_hosts_params = {
@@host { $real_hosts:
ensure => $hosts_ensure,
ip => '127.0.0.1',
tag => $tags,
}

webapp::instance::create_host { $real_hosts :
prefix => $prefix,
params => $real_hosts_params,
}
}
}

####################################################################[ Cron ]###
if !empty($cron) {
create_resources("${prefix}cron", $cron, {'tag' => $tags})
$cron.each | String $name, Hash $params| {
@@cron { $name:
tag => $tags,
* => $params,
}
}

################################################################[ Database ]###
Expand All @@ -361,20 +328,22 @@
validate_slength($real_db_name, 64)
validate_slength($real_db_user, 16)

$mysql_db_params = {
@@mysql::db { $real_db_name:
ensure => $db_ensure,
user => $real_db_user,
password => $real_db_pass,
host => '%',
tag => $tags,
}
if !defined(Mysql::Db[$real_db_name]) {
create_resources("${prefix}mysql::db", { "${real_db_name}" => $mysql_db_params } )
}

if !empty($db_grants) {
validate_hash($db_grants)
create_resources("${prefix}mysql_grant", $db_grants, {'tag' => $tags} )
$db_grants.each | String $name, Hash $params| {
@@mysql_grant { $name:
tag => $tags,
* => $params,
}
}
}

}
Expand All @@ -389,23 +358,13 @@
$real_solr_folder = pick($solr_folder, $real_docroot_folder)
$solr_directory = "${real_solr_prefix}/${real_solr_folder}/${solr_suffix}"

$solr_instance_params = {
@@solr::instance { $solr_name:
ensure => $solr_ensure,
directory => $solr_directory,
version => $solr_version,
initialize => $solr_initialize,
tag => $tags,
}

if !defined(Solr::Instance[$solr_name]) {
create_resources("${prefix}solr::instance", { "${solr_name}" => $solr_instance_params } )
}
}
}

define webapp::instance::create_host($prefix, $params) {
if !defined(Host[$name]) {
create_resources("${prefix}host", { "${name}" => $params } )
}
}