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
|
# File 'manifests/config/server/host.pp', line 24
define tomcat::config::server::host (
$app_base = undef,
Optional[Stdlib::Absolutepath] $catalina_base = undef,
Enum['present','absent'] $host_ensure = 'present',
$host_name = undef,
String $parent_service = 'Catalina',
Hash $additional_attributes = {},
Array $attributes_to_remove = [],
Optional[String] $server_config = undef,
Optional[Array] $aliases = undef,
Boolean $show_diff = true,
) {
include ::tomcat
$_catalina_base = pick($catalina_base, $::tomcat::catalina_home)
tag(sha1($_catalina_base))
if versioncmp($::augeasversion, '1.0.0') < 0 {
fail('Server configurations require Augeas >= 1.0.0')
}
if $host_name {
$_host_name = $host_name
} else {
$_host_name = $name
}
$base_path = "Server/Service[#attribute/name='${parent_service}']/Engine/Host[#attribute/name='${_host_name}']"
if $server_config {
$_server_config = $server_config
} else {
$_server_config = "${_catalina_base}/conf/server.xml"
}
if $host_ensure == 'absent' or $host_ensure == false {
$changes = "rm ${base_path}"
} else {
if ! $app_base {
fail('$app_base must be specified if you aren\'t removing the host')
}
$_host_name_change = "set ${base_path}/#attribute/name ${_host_name}"
$_app_base = "set ${base_path}/#attribute/appBase ${app_base}"
if ! empty($additional_attributes) {
$_additional_attributes = suffix(prefix(join_keys_to_values($additional_attributes, " '"), "set ${base_path}/#attribute/"), "'")
} else {
$_additional_attributes = undef
}
if ! empty(any2array($attributes_to_remove)) {
$_attributes_to_remove = prefix(any2array($attributes_to_remove), "rm ${base_path}/#attribute/")
} else {
$_attributes_to_remove = undef
}
if $aliases {
$_clear_aliases = "rm ${base_path}/Alias"
$_add_aliases = suffix(prefix($aliases, "set ${base_path}/Alias[last()+1]/#text '"), "'")
} else {
$_clear_aliases = undef
$_add_aliases = undef
}
$changes = delete_undef_values(flatten([
$_host_name_change,
$_app_base,
$_additional_attributes,
$_attributes_to_remove,
$_clear_aliases,
$_add_aliases,
]))
}
augeas { "${_catalina_base}-${parent_service}-host-${name}":
lens => 'Xml.lns',
incl => $_server_config,
changes => $changes,
show_diff => $show_diff,
}
}
|