DevOps Classroom Series – 05/Sept/2020

tomcat cookbook with out apt (contd..)

  • The cookbook is available at here

  • This cookbook is developed based on documentation refer Here

  • Problems with above cookbook:

    1. Configuration files are assumed to be static
      • tomcat-users.xml
      • tomcat.service
    2. This cookbook as of now will work on ubuntu systems only. Need to implement redhat flavor atleast
    3. Tests are using the package names which are hardcoded
  • Chef gives us two ways to verify whether our cookbook is meeting standards or not

  • Understand the changes done by executing cookstyle -a

Chef Templates

  • Chef templates can be created with chef generate command
chef generate template --help
chef generate template . tomcat-users.xml

Preview Preview

  • Refer Here for embedded ruby templating.
  • Using erb the tomcat-users.xml.erb will be
<?xml version="1.0" encoding="UTF-8"?>
  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

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  See the License for the specific language governing permissions and
  limitations under the License.
<tomcat-users xmlns=""
              xsi:schemaLocation=" tomcat-users.xsd"
  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. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
	<user username="<%= node['tomcat9']['adminuser'] %>" password="<%= node['tomcat9']['adminpassword'] %>" roles="<%= node['tomcat9']['adminroles'] %>"/>

  • Exercise: Try to create template for tomcat.service
  • Replace
    • this
    cookbook_file tomcat_users_location do
        source 'tomcat-users.xml'
        action :create
        notifies :restart, 'service[tomcat]'
    • with
    template 'tomcat_users_location' do
    source 'tomcat-users.xml.erb'
    action :create
    notifies :restart, 'service[tomcat]'

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin