Defined Type: tomcat::config::server::context

Defined in:
manifests/config/server/context.pp

Summary

Configure a Context element in $CATALINA_BASE/conf/server.xml

Overview

Parameters:

  • catalina_base (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Specifies the base directory of the Tomcat installation to manage. Valid options: a string containing an absolute path.

  • context_ensure (Enum['present','absent']) (defaults to: 'present')

    Specifies whether the [Context XML element](tomcat.apache.org/tomcat-8.0-doc/config/context.html) should exist in the configuration file.

  • doc_base (Optional[String[1]]) (defaults to: undef)

    Specifies a Document Base (or Context Root) directory or archive file. Maps to the [docBase XML attribute](tomcat.apache.org/tomcat-8.0-doc/config/context.html#Common_Attributes). Valid options: a string containing a path (either an absolute path or a path relative to the appBase directory of the owning Host). ‘$name`.

  • parent_service (Optional[String[1]]) (defaults to: undef)

    Specifies which Service XML element the Context should nest under. Valid options: a string containing the name attribute of the Service.

  • parent_engine (Optional[String[1]]) (defaults to: undef)

    Specifies which Engine element the Context should nest under. Only valid if ‘parent_host` is specified. Valid options: a string containing the name attribute of the Engine.

  • parent_host (Optional[String[1]]) (defaults to: undef)

    Specifies which Host element the Context should nest under. Valid options: a string containing the name attribute of the Host.

  • additional_attributes (Hash) (defaults to: {})

    Specifies any further attributes to add to the Context. Valid options: a hash of ‘< attribute >’ => ‘< value >’ pairs.

  • attributes_to_remove (Array) (defaults to: [])

    Specifies an array of attributes to remove from the element. Valid options: an array of strings.

  • server_config (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Specifies a server.xml file to manage. Valid options: a string containing an absolute path.

  • show_diff (Boolean) (defaults to: true)

    Specifies display differences when augeas changes files, defaulting to true. Valid options: true or false.



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
# File 'manifests/config/server/context.pp', line 24

define tomcat::config::server::context (
  Optional[Stdlib::Absolutepath] $catalina_base         = undef,
  Enum['present','absent']       $context_ensure        = 'present',
  Optional[String[1]]            $doc_base              = undef,
  Optional[String[1]]            $parent_service        = undef,
  Optional[String[1]]            $parent_engine         = undef,
  Optional[String[1]]            $parent_host           = undef,
  Hash                           $additional_attributes = {},
  Array                          $attributes_to_remove  = [],
  Optional[Stdlib::Absolutepath] $server_config         = undef,
  Boolean                        $show_diff             = true,
) {
  include tomcat
  $_catalina_base = pick($catalina_base, $tomcat::catalina_home)
  tag(sha1($_catalina_base))

  if versioncmp($facts['augeas']['version'], '1.0.0') < 0 {
    fail('Server configurations require Augeas >= 1.0.0')
  }

  if $doc_base {
    $_doc_base = $doc_base
  } else {
    $_doc_base = $name
  }

  if $parent_service {
    $_parent_service = $parent_service
  } else {
    $_parent_service = 'Catalina'
  }

  if $parent_engine and ! $parent_host {
    warning('context elements cannot be nested directly under engine elements, ignoring $parent_engine')
  }

  if $parent_engine and $parent_host {
    $_parent_engine = $parent_engine
  } else {
    $_parent_engine = undef
  }

  if $server_config {
    $_server_config = $server_config
  } else {
    $_server_config = "${_catalina_base}/conf/server.xml"
  }

  # lint:ignore:140chars
  if $parent_host and ! $_parent_engine {
    $path = "Server/Service[#attribute/name='${_parent_service}']/Engine/Host[#attribute/name='${parent_host}']/Context[#attribute/docBase='${_doc_base}']"
  } elsif $parent_host and $_parent_engine {
    $path = "Server/Service[#attribute/name='${_parent_service}']/Engine[#attribute/name='${_parent_engine}']/Host[#attribute/name='${parent_host}']/Context[#attribute/docBase='${_doc_base}']"
  } else {
    $path = "Server/Service[#attribute/name='${_parent_service}']/Engine/Host/Context[#attribute/docBase='${_doc_base}']"
  }
  # lint:endignore

  if $context_ensure == 'absent' {
    $augeaschanges = "rm ${path}"
  } else {
    $context = "set ${path}/#attribute/docBase ${_doc_base}"

    if ! empty($additional_attributes) {
      $_additional_attributes = suffix(prefix(join_keys_to_values($additional_attributes, " '"), "set ${path}/#attribute/"), "'")
    } else {
      $_additional_attributes = undef
    }

    if ! empty(any2array($attributes_to_remove)) {
      $_attributes_to_remove = prefix(any2array($attributes_to_remove), "rm ${path}/#attribute/")
    } else {
      $_attributes_to_remove = undef
    }

    $augeaschanges = delete_undef_values(flatten([$context, $_additional_attributes, $_attributes_to_remove]))
  }

  augeas { "${_catalina_base}-${_parent_service}-${_parent_engine}-${parent_host}-context-${name}":
    lens      => 'Xml.lns',
    incl      => $_server_config,
    changes   => $augeaschanges,
    show_diff => $show_diff,
  }
}