2
votes

I made a puppet class to install Apache Tomcat 7.55 in my node, but I do not know how to configure a datasource in it.

The last step of my class is to deploy an application:

tomcat::war { 'my.war':
    catalina_base => '/opt/apache-tomcat/tomcat_7_0_55',
    war_source    => '/etc/puppet/resources/my.war',
  }

After this step, I need to configure the following datasource in conf/server.xml file:

 <Context path="/my-app" docBase="my-app" debug="5" reloadable="true" crossContext="true">
                 <Resource name="jdbc/my-app-db" auth="Container" 
                          type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="5"
                          username="xxx" password="yyy"
                          driverClassName="com.mysql.jdbc.Driver"
                          url="jdbc:mysql://<host>:3306/<database>?zeroDateTimeBehavior=convertToNull"/>
</Context>

How can I do this through Puppet? I am using puppetlabs-tomcat module.

Thanks!

3
Try using tomcat::config::server::connector.jordanm
Hi, jordanm. Thanks for the reply! I read the documentation at forge.puppetlabs.com/puppetlabs/… but could not find anything suitable to configure as datasource. Also, isn't a tomcat's connector an intermediary between Catalina (the tomcat's servlet implementation) and the web applications, like HTTP Connector?Quaestor Lucem

3 Answers

4
votes

you can create a template for the server.xml file, and set file type as below

$mysql_username = xxx
$mysql_password = yyy
$mysql_server = zzz

file { "${install_path}/conf/server.xml" :
    ensure  => present,
    content => template('tomcat/server.xml.erb'),
    owner   => 'tomcat',
    group   => 'tomcat,
    mode    => '0644',
    notify  => 'Class[tomcat::service]',
}

The tomcat/template/server.xml.erb should include the content as

.... blabla

 <Context path="/my-app" docBase="my-app" debug="5" reloadable="true" crossContext="true">
                 <Resource name="jdbc/my-app-db" auth="Container" 
                          type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="5"
                          username="<%= @mysql_username %>" password="<%= @mysql_password %>"
                          driverClassName="com.mysql.jdbc.Driver"
                          url="jdbc:mysql://<%= @mysql_server %>:3306/<database>?zeroDateTimeBehavior=convertToNull"/>
</Context>

.... blabla
2
votes

You can use augeas tool with xml lens to configure this inside server.xml. You need to have augeas module installed with puppet though.

0
votes

Here is an example config

tomcat::config::server::context {'alfresco.war':
doc_base => 'alfresco.war',
context_ensure => present,
catalina_base => '/var/lib/tomcat7/alfresco.war',
parent_service        => 'Catalina',
parent_engine         => 'Catalina',
parent_host           => 'localhost',
server_config         => '/etc/tomcat7/server.xml',
additional_attributes => {
          'path' => '/alfresco',
        },
}