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

Missing dep for Red Hat source installation. Hostmanager and manager support. Handling of tomcat-users.xml #152

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
# server.xml
# - *catalina_logrotate*: install an UNMANAGED logrotate configuration file,
# to handle the catalina.out file of the instance. Default to true.
# - *hostmanager*: if "true" it will enable deploy of hostmanager webapp.
# - *manager*: if "true" it will enable deploy of manager webapp.
# - *users*: Array of hashes containing structure like [ {username => "user", password => "secret", roles="manager-gui,admin"} ], needed for hostmanager webapp.
# - *roles*: Array of string containing roles to be placed in tomcat-users.xml, needed for hostmanager webapp.
#
# Requires:
# - one of the tomcat classes which installs tomcat binaries.
Expand Down Expand Up @@ -93,6 +97,21 @@
# ],
# }
#
# tomcat::instance { "bar":
# ensure => present,
# server_port => 8006,
# http_port => 8081,
# ajp_port => 8010,
# users => [
# {
# username => "myuser"
# password => "mypassword"
# roles => "manager-gui,admin"
# }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma

# ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma

# roles => [ manager-gui, admin ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma

# }
#
define tomcat::instance(
$ensure = present,
$owner = 'tomcat',
Expand Down Expand Up @@ -123,6 +142,10 @@
$tomcat_version = $tomcat::version,
$catalina_logrotate = true,
$java_opts = undef,
$hostmanager = false,
$manager = false,
$users = [],
$roles = [],
) {

Class['tomcat::install'] -> Tomcat::Instance[$title]
Expand Down Expand Up @@ -156,6 +179,8 @@
owner => $owner,
sample => $sample,
webapp_mode => $webapp_mode,
hostmanager => $hostmanager,
manager => $manager,
}

tomcat::instance::config { $title:
Expand Down Expand Up @@ -184,6 +209,10 @@
version => $version,
web_xml_file => $web_xml_file,
java_opts => $java_opts,
hostmanager => $hostmanager,
manager => $manager,
users => $users,
roles => $roles,
}

tomcat::instance::service { $title:
Expand Down
65 changes: 65 additions & 0 deletions manifests/instance/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
$server_xml_file = undef,
$web_xml_file = undef,
$java_opts = undef,
$hostmanager = false,
$manager = false,
$users = [],
$roles = [],
) {
# lint:ignore:only_variable_string
validate_re("${server_port}", '^[0-9]+$')
Expand All @@ -34,6 +38,9 @@
validate_array($setenv)
validate_array($connector)
validate_array($executor)
validate_array($users)
validate_array($roles)


###
# Configure connectors
Expand Down Expand Up @@ -207,6 +214,64 @@
mode => '0574',
}

###
# Configure hostmanager & manager webapps
#

if !$tomcat::sources {
$webapps_base = $::osfamily ? {
'RedHat' => $::operatingsystemmajrelease ? {
'7' => '/var/lib/tomcat/server/webapps',
default => "/var/lib/tomcat${tomcat::version}/server/webapps",
},
'Debian' => "/usr/share/tomcat${tomcat::version}-admin",
}
}else {
$webapps_base = '/opt/apache-tomcat/webapps'
}


if $manager {
file { "${catalina_base}/webapps/manager":
ensure => link,
target => "${webapps_base}/manager",
}
}elsif ($manage){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces

file { "${catalina_base}/webapps/manager":
ensure => absent,
}
}
Copy link
Contributor

@raphink raphink Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather declare this file in one place only, and change the ensure parameter value depending on $manager.


if $hostmanager {
file { "${catalina_base}/webapps/host-manager":
ensure => link,
target => "${webapps_base}/host-manager",
}
}elsif ($manage){
file { "${catalina_base}/webapps/host-manager":
ensure => absent,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as l.243


###
# Configure users auth
#
if ($users or $roles){
file { "${catalina_base}/conf/tomcat-users.xml":
ensure => file,
owner => $owner,
group => $group,
mode => '0664',
source => undef,
content => template("${module_name}/tomcat-users.xml.erb"),
replace => $manage,
}
}elsif (!$users and !$roles and $manage){
file { "${catalina_base}/conf/tomcat-users.xml":
ensure => absent,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and same here again


###
# Configure Init script
#
Expand Down
13 changes: 13 additions & 0 deletions manifests/instance/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
$conf_mode = undef,
$sample = undef,
$webapp_mode = undef,
$hostmanager = undef,
$manager = undef,
) {

if defined(File[$tomcat::instance_basedir]) {
Expand Down Expand Up @@ -138,6 +140,17 @@
content => file(sprintf('%s/files/sample.war', get_module_path($module_name))),
}
}
if ($manager or $hostmanager) {
if !$tomcat::sources {
$packageweb_name = $::osfamily ? {
'RedHat' => $::operatingsystemmajrelease ? {
'7' => 'tomcat-admin-webapps',
default => "tomcat${tomcat::version}-admin-webapps",
},
'Debian' => "tomcat${tomcat::version}-admin",
}
}
}
}
'absent': {
file { $catalina_base:
Expand Down
7 changes: 7 additions & 0 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
fail("Use of private class ${name} by ${caller_module_name}")
}

if ( $::osfamily == 'RedHat' ){
package {'redhat-lsb-core':
ensure => installed,
name => 'redhat-lsb-core',
}
}

$version = $tomcat::src_version
$sources_src = $tomcat::sources_src

Expand Down
40 changes: 40 additions & 0 deletions templates/tomcat-users.xml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- file created and managed by puppet -->
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<tomcat-users>
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
-->
<!--
NOTE: The sample user and role entries below are wrapped in a comment
and thus are ignored when reading this file. Do not forget to remove
<!.. ..> that surrounds them.
-->

<% @roles.each do |role| -%>
<role rolename="<%= role %>"/>
<% end -%>

<% @users.each do |userhash| -%>
<user username="<%= userhash['username'] %>" password="<%= userhash['password'] %>" roles="<%= userhash['roles'] %>"/>
<% end -%>

</tomcat-users>