With Puppet, the declarative configuration of systems can easily be managed. Our task is just to declare the available resources of the system, and then declare their state too. We then store the description in the Puppet’s core files. In this chapter, we will guide you on how to define TomEE as a resource of Puppet and this will mean that it will be automatically installed in all computers which are under the management of Puppet. Note that the TomEE was written in Java programming language, which means that JDK must be installed in your system for you to succeed in this chapter. To easily install the package into your system, just use the package manager.
We need to begin by creating a manifest file named “init.php” and then create an exec task which will update the package manager with the list of the available packages. This should have the following code:
# updating the (outdated) package list
exec { ‘update-package-list’:
command => ‘usrbinsudo usrbinapt-get update’,
}
A class should next be defined, and then tasked with the installation of the OpenJDK. In Puppet, a class means several resources put together, and then Puppet will view them as a single unit. This is shown below:
class java { package { “openjdk-6-jdk”: ensure => installed, require => Exec[“update-package-list”], } }
The next step should involve installation of the TomEE. Right now, it is not available in your distribution package repository in a software format. This means that a different approach is needed to the one which is followed in OpenJDK. We want to visit the TomEE site, and then download the “tar.gz” file which we will extract into our installation directory. The code for doing this is given below:
class tom {
file {“/opt/tomee-1.5.1”:
ensure => directory,
recurse => true,
} ->
exec { “download-tomee” :
command => “/usr/bin/wget https://apache.rediris.es/openejb/openejb-4.5.1/apache-tomee-1.5.1-
webprofile.tar.gz -O
/tmp/tomee-1.5.1.tar.gz”,
creates => “/tmp/tomee-1.5.1.tar.gz”,
} ->
exec { “unpack-tomee” :
command => “/bin/tar -xzf /tmp/tomee-1.5.1.tar.gz -C /opt/tomee-1.5.1 –strip-components=1”,
creates => “/opt/tomee-1.5.1/bin”,
}
}
We have created a class named “tom” and then the directory in which the TomEE will be installed. The TomEE has been downloaded from the Apache site by use of the “wget” command, and the file is downloaded in a compressed format. We have then uncompressed the file in the directory which we have just created.
Frequently Asked Puppet Interview Questions & Answers
At this point, the Apache TomEE has already been installed into the computer, but to start and stop it, this is not done automatically. To make the TomEE available, we must execute the command “/opt/tomee-1.5.1/bin/startup.sh.” We can change this by use of the service resource. What it does is that an installed service is registered as a service. The next service resource should be defined in the TomEE class as follows:
service { “tomee” :
provider => “init”,
ensure => running,
start => “/opt/tomee-1.5.1/bin/startup.sh”,
stop => “/opt/tomee-1.5.1/bin/shutdown.sh”,
status => “”,
restart => “”,
hasstatus => false,
hasrestart => false,
require => [ Exec[“unpack-tomee”], Package[“openjdk-6-jdk”] ],
}
When it comes to a service resource, one must have the TomEE unpacked and the OpnJDK installed, and this is why we have two declarations in the required attribute. The Puppet will create attributes in the “exec” task, and this will determine if a task is to be executed or not.
Name | Dates | |
---|---|---|
Puppet Training | Nov 02 to Nov 17 | View Details |
Puppet Training | Nov 05 to Nov 20 | View Details |
Puppet Training | Nov 09 to Nov 24 | View Details |
Puppet Training | Nov 12 to Nov 27 | View Details |
Ravindra Savaram is a Technical Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.