Defined Type: tomcat::config::context::environment

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

Summary

Configure Environment elements in $CATALINA_BASE/conf/context.xml

Overview

Parameters:

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

    Specifies whether you are trying to add or remove the Environment element Valid options: ‘present’, ‘absent’.

  • catalina_base (Stdlib::Absolutepath) (defaults to: $::tomcat::catalina_home)

    Specifies the root of the Tomcat installation.

  • environment_name (String) (defaults to: $name)

    The name of the Environment Entry to be created, relative to the ‘java:comp/env` context. `$name`.

  • name

    ‘$environment_name`

  • type (Optional[String]) (defaults to: undef)

    The fully qualified Java class name expected by the web application for this environment entry. Required to create the environment entry.

  • value (Optional[String]) (defaults to: undef)

    The value that will be presented to the application when requested from the JNDI context. Required to create the environment entry.

  • description (Optional[String]) (defaults to: undef)

    The description is an an optional string for a human-readable description of this environment entry.

  • override (Optional[Boolean]) (defaults to: undef)

    An optional string or Boolean to specify if you do not want an ‘<env-entry>` for the same environment entry name to override the value specified here (set it to `false`). By default, overrides are allowed.

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

    Specifies any additional attributes to add to the Environment. Should be a hash of the format ‘attribute’ => ‘value’.

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

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

  • show_diff (Boolean) (defaults to: true)

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



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

define tomcat::config::context::environment (
  Enum['present','absent'] $ensure    = 'present',
  Stdlib::Absolutepath $catalina_base = $::tomcat::catalina_home,
  String $environment_name            = $name,
  Optional[String] $type              = undef,
  Optional[String] $value             = undef,
  Optional[String] $description       = undef,
  Optional[Boolean] $override         = undef,
  Hash $additional_attributes         = {},
  Array $attributes_to_remove         = [],
  Boolean $show_diff                  = true,
) {
  if versioncmp($::augeasversion, '1.0.0') < 0 {
    fail('Server configurations require Augeas >= 1.0.0')
  }

  $base_path = "Context/Environment[#attribute/name='${environment_name}']"

  if $ensure == 'absent' {
    $changes = "rm ${base_path}"
  } else {
    if empty($type) {
      fail('$type must be specified')
    }

    if empty($value) {
      fail('$value must be specified')
    }

    $set_name  = "set ${base_path}/#attribute/name '${environment_name}'"
    $set_type  = "set ${base_path}/#attribute/type '${type}'"
    $set_value = "set ${base_path}/#attribute/value '${value}'"

    if $override != undef {
      $_override = bool2str($override)
      $set_override = "set ${base_path}/#attribute/override ${_override}"
    } else {
      $set_override = "rm ${base_path}/#attribute/override"
    }

    if ! empty($description) {
      $set_description = "set ${base_path}/#attribute/description \'${description}\'"
    } else {
      $set_description = "rm ${base_path}/#attribute/description"
    }

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

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

    $changes = delete_undef_values(flatten([
      $set_name,
      $set_type,
      $set_value,
      $set_override,
      $set_description,
      $set_additional_attributes,
      $rm_attributes_to_remove,
    ]))
  }

  augeas { "context-${catalina_base}-environment-${name}":
    lens      => 'Xml.lns',
    incl      => "${catalina_base}/conf/context.xml",
    changes   => $changes,
    show_diff => $show_diff,
  }
}