* If tomcat8 is already installed and running,just do not do anything.
* If tomcat server.xml is changed, restart service.
* Test
1. Change 8080 default tomcat port to 8081
2. On each test with netstat command.
###################################################
Tuesday, April 14, 2015
Monday, April 13, 2015
Puppet3.7.5 Tomcat8 installation automation
Puppet3.7.5 Tomcat8 installation automation
Centos7,Ubuntu14.04 Test by puppet automation? framework.
*Todo: separation of env variables to other file.pp
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat init.pp
class tomcat8 {
include tomcat8::account_add
$instance_owner = "tomcat8"
$instance_group = "tomcat8"
$java_opts = "-Djava.awt.headless=true -Xmx128M -XX:+UseConcMarkSweepGC"
#$java_opts = "-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m"
$catalina_home = "/usr/local/tomcat8"
$catalina_base = "/usr/local/tomcat8"
$catalina_pid= "/usr/local/tomcat8/tomcat8.pid"
$java_security_manager = "no"
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
#java install
class { 'java': }
$java_home = "/usr/local/java"
$instance_name = "centos7-tomcat8"
#In case of new config as in tomcat8
include tomcat8::centos7_config
# do something RHEL specific
# execute 'yum update'
#exec { 'yum-update':
# command => '/bin/yum -y update'
#}
include tomcat8::get_tomcat
#running service
exec { 'tomcat8-start':
path => ['/bin','/usr/bin','/usr/sbin','/sbin'],
command => 'systemctl daemon-reload && systemctl start tomcat8 && systemctl enable tomcat8',
}
}
'ubuntu': {
#java install
class { 'java': }
#In case of new config as in tomcat8
include tomcat8::ubuntu_config
#tomcat version and compressed file
$java_home = "/usr/lib/jvm/java-7-oracle"
$default_file = "/etc/default/tomcat8"
$instance_name = "ubuntu-trusty-tomcat8"
include tomcat8::get_tomcat
# running tomcat8
service { 'tomcat8':
ensure => running,
}
}
default: {
# ...
}
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat get_tomcat.pp
class tomcat8::get_tomcat {
$TOMCAT="apache-tomcat"
$TOMCAT_DIR="tomcat-8"
$TOMCAT_VERSION="8.0.21"
$COMP=".tar.gz"
$INSTALL_DIR="/usr/local/tomcat8"
$POLICY_DIR="$INSTALL_DIR/conf/policy.d"
$instance_owner = "tomcat8"
$instance_group = "tomcat8"
exec { 'wget-tomcat':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
#using mirror
#command => "wget http://mirrors.advancedhosters.com/apache/tomcat/$TOMCAT_DIR/v$TOMCAT_VERSION/bin/$TOMCAT-$TOMCAT_VERSION$COMP",
#using local web server
command => "wget http://10.0.0.100/$TOMCAT-$TOMCAT_VERSION$COMP && tar xvzf $TOMCAT-$TOMCAT_VERSION$COMP",
unless => "ls /tmp/$TOMCAT-$TOMCAT_VERSION",
}
exec { 'tomcat-install':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
command => "mv $TOMCAT-$TOMCAT_VERSION $INSTALL_DIR && mkdir $POLICY_DIR && chown -R $instance_owner:$instance_group $INSTALL_DIR && chmod 0755 $INSTALL_DIR/conf && chown -R root:root $INSTALL_DIR/conf && chown -R root:$instance_group $INSTALL_DIR/conf/* && chmod 644 $INSTALL_DIR/conf/* && chmod 0755 $POLICY_DIR",
unless => "ls $INSTALL_DIR",
require => Exec['wget-tomcat'],
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat centos7_config.pp
class tomcat8::centos7_config {
file { "/etc/systemd/system/tomcat8.service":
ensure => present,
owner => 'root',
group => 'root',
mode => 0700,
#enable => true,
content => template('tomcat8/centos7-tomcat8.erb'),
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat account_add.pp
class tomcat8::account_add {
user { "tomcat8":
comment => "tomcat8user",
home => "/usr/local/tomcat8",
managehome => "false",
shell => "/bin/false",
uid => 109,
gid => 118,
}
group { "tomcat8":
gid => 118,
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat ubuntu_config.pp
class tomcat8::ubuntu_config {
file { "/etc/init.d/tomcat8":
ensure => present,
owner => 'root',
group => 'root',
mode => 0755,
content => template('tomcat8/ubuntu-tomcat8.erb'),
}
file { "/etc/default/tomcat8":
ensure => present,
owner => 'root',
group => 'root',
mode => 0640,
content => template('tomcat8/ubuntu-default-tomcat8.erb'),
}
}
root@puppet:/etc/puppet/modules/tomcat8# cat templates/centos7-tomcat8.erb
[Unit]
Description=Tomcat8
After=network.target
[Service]
Type=forking
User=<%= @instance_owner %>
Group=<%= @instance_group %>
Environment=CATALINA_PID=<%= @catalina_pid %>
Environment=JAVA_HOME=<%= @java_home %>
Environment=TOMCAT_JAVA_HOME=<%= @java_home %>
Environment=CATALINA_HOME=<%= @catalina_home %>
Environment=CATALINA_BASE=<%= @catalina_base %>
Environment=CATALINA_OPTS=
Environment="JAVA_OPTS=<%= @java_opts %>"
ExecStart=<%= @catalina_home %>/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
[Install]
WantedBy=multi-user.target
root@puppet:/etc/puppet/modules/tomcat8# cat templates/ubuntu-default-tomcat8.erb
# File Managed by Puppet
# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat7.
TOMCAT8_USER=<%= @instance_owner %>
# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat7.
TOMCAT8_GROUP=<%= @instance_group %>
# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
<% if @java_home != '' -%>
JAVA_HOME=<%= @java_home %>
<% end -%>
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
<% if @java_opts != '' -%>
JAVA_OPTS="<%= @java_opts %>"
<% end -%>
#<% if @catalina_opts != '' -%>
#CATALINA_OPTS="<%= @catalina_opts %>"
#<% end -%>
# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=javac
# Use the Java security manager? (yes/no, default: no)
#TOMCAT8_SECURITY=no
# Number of days to keep logfiles in /var/log/tomcat7. Default is 14 days.
#LOGFILE_DAYS=14
# Location of the JVM temporary directory
# WARNING: This directory will be destroyed and recreated at every startup !
#JVM_TMP=/tmp/tomcat7-temp
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no
root@puppet:/etc/puppet/modules/tomcat8# cat templates/ubuntu-default-tomcat8.erb
# File Managed by Puppet
# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat7.
TOMCAT8_USER=<%= @instance_owner %>
# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat7.
TOMCAT8_GROUP=<%= @instance_group %>
# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
<% if @java_home != '' -%>
JAVA_HOME=<%= @java_home %>
<% end -%>
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
<% if @java_opts != '' -%>
JAVA_OPTS="<%= @java_opts %>"
<% end -%>
#<% if @catalina_opts != '' -%>
#CATALINA_OPTS="<%= @catalina_opts %>"
#<% end -%>
# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=javac
# Use the Java security manager? (yes/no, default: no)
#TOMCAT8_SECURITY=no
# Number of days to keep logfiles in /var/log/tomcat7. Default is 14 days.
#LOGFILE_DAYS=14
# Location of the JVM temporary directory
# WARNING: This directory will be destroyed and recreated at every startup !
#JVM_TMP=/tmp/tomcat7-temp
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no
root@puppet:/etc/puppet/modules/tomcat8# cat templates/ubuntu-
ubuntu-default-tomcat8.erb ubuntu-tomcat8.erb
root@puppet:/etc/puppet/modules/tomcat8# cat templates/ubuntu-tomcat8.erb
#!/bin/sh
# File Managed by Puppet
#
# Modification of https://raw.githubusercontent.com/example42/puppet-tomcat/master/templates/instance/init7-Debian.erb
# /etc/init.d/tomcat8 -- startup script for the Tomcat 8 servlet engine
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Tomcat by Stefan Gybas <sgybas@debian.org>.
# Modified for Tomcat6 by Thierry Carrez <thierry.carrez@ubuntu.com>.
# Modified for Tomcat7 by Ernesto Hernandez-Novich <emhn@itverx.com.ve>.
# Modified for Tomcat8 by OhYoungJooung <wnapdlf05@gmail.com>.
# Additional improvements by Jason Brittain <jason.brittain@mulesoft.com>.
#
### BEGIN INIT INFO
# Provides: tomcat8-<%= @instance_name %>
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Tomcat.
# Description: Start the Tomcat servlet engine.
### END INIT INFO
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=`basename $0`
DESC="Tomcat8 servlet engine"
DEFAULT=/etc/default/$NAME
JVM_TMP=/tmp/tomcat8-$NAME-tmp
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
# Make sure tomcat is started with system locale
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG
fi
. /lib/lsb/init-functions
if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi
# The following variables can be overwritten in $DEFAULT
# Run Tomcat 8 as this user ID and group ID
TOMCAT8_USER=<%= @instance_owner %>
TOMCAT8_GROUP=<%= @instance_group %>
# this is a work-around until there is a suitable runtime replacement
# for dpkg-architecture for arch:all packages
# this function sets the variable OPENJDKS
find_openjdks()
{
for jvmdir in /usr/lib/jvm/java-7-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ]
then
OPENJDKS=$jvmdir
fi
done
for jvmdir in /usr/lib/jvm/java-6-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ]
then
OPENJDKS="${OPENJDKS} ${jvmdir}"
fi
done
}
OPENJDKS=""
find_openjdks
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT)
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-7-oracle"
# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
# Directory where the Tomcat 6 binary distribution resides
CATALINA_HOME=<%= @catalina_home %>
# Directory for per-instance configuration files and webapps
CATALINA_BASE=<%= @catalina_base %>
# Use the Java security manager? (yes/no)
TOMCAT8_SECURITY=<%= @java_security_manager %>
# Default Java options
# Set java.awt.headless=true if JAVA_OPTS is not set so the
# Xalan XSL transformer can work without X11 display on JDK 1.4+
# It also looks like the default heap size of 64M is not enough for most cases
# so the maximum heap size is set to 128M
if [ -z "$JAVA_OPTS" ]; then
JAVA_OPTS="<%= @java_opts %>"
fi
# End of variables that can be overwritten in $DEFAULT
# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. <%= $default_File %>
fi
if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then
log_failure_msg "$NAME is not installed"
exit 1
fi
POLICY_CACHE="$CATALINA_BASE/work/catalina.policy"
if [ -z "$CATALINA_TMPDIR" ]; then
CATALINA_TMPDIR="$JVM_TMP"
fi
# Set the JSP compiler if set in the tomcat8.default file
if [ -n "$JSP_COMPILER" ]; then
JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\""
fi
SECURITY=""
if [ "$TOMCAT8_SECURITY" = "yes" ]; then
SECURITY="-security"
fi
# Define other required variables
CATALINA_PID="/var/run/$NAME.pid"
CATALINA_SH="$CATALINA_HOME/bin/catalina.sh"
# Look for Java Secure Sockets Extension (JSSE) JARs
if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then
JSSE_HOME="${JAVA_HOME}/jre/"
fi
catalina_sh() {
# Escape any double quotes in the value of JAVA_OPTS
JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')"
AUTHBIND_COMMAND=""
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c "
fi
# Define the command to run Tomcat's catalina.sh as a daemon
# set -a tells sh to export assigned variables to spawned shells.
TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \
CATALINA_HOME=\"$CATALINA_HOME\"; \
CATALINA_BASE=\"$CATALINA_BASE\"; \
JAVA_OPTS=\"$JAVA_OPTS\"; \
CATALINA_PID=\"$CATALINA_PID\"; \
CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \
LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \
cd \"$CATALINA_BASE\"; \
\"$CATALINA_SH\" $@"
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
TOMCAT_SH="'$TOMCAT_SH'"
fi
# Run the catalina.sh script as a daemon
set +e
touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
chown $TOMCAT8_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
start-stop-daemon --start -b -u "$TOMCAT8_USER" -g "$TOMCAT8_GROUP" \
-c "$TOMCAT8_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \
-x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
status="$?"
set +a -e
return $status
}
case "$1" in
start)
if [ -z "$JAVA_HOME" ]; then
log_failure_msg "no JDK found - please set JAVA_HOME"
exit 1
fi
if [ ! -d "$CATALINA_BASE/conf" ]; then
log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
exit 1
fi
log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
# Regenerate POLICY_CACHE file
umask 022
echo "// AUTO-GENERATED FILE from /etc/tomcat8/policy.d/" \
> "$POLICY_CACHE"
echo "" >> "$POLICY_CACHE"
if [ $(ls -1 $CATALINA_BASE/conf/policy.d/ | grep ".policy$" | wc -l) -ne 0 ]; then
cat $CATALINA_BASE/conf/policy.d/*.policy \
>> "$POLICY_CACHE"
fi
# Remove / recreate JVM_TMP directory
rm -rf "$JVM_TMP"
mkdir -p "$JVM_TMP" || {
log_failure_msg "could not create JVM temporary directory"
exit 1
}
chown $TOMCAT8_USER "$JVM_TMP"
catalina_sh start $SECURITY
sleep 5
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
if [ -f "$CATALINA_PID" ]; then
rm -f "$CATALINA_PID"
fi
log_end_msg 1
else
log_end_msg 0
fi
else
log_progress_msg "(already running)"
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
set +e
if [ -f "$CATALINA_PID" ]; then
start-stop-daemon --stop --pidfile "$CATALINA_PID" \
--user "$TOMCAT8_USER" \
--retry=TERM/20/KILL/5 >/dev/null
if [ $? -eq 1 ]; then
log_progress_msg "$DESC is not running but pid file exists, cleaning up"
elif [ $? -eq 3 ]; then
PID="`cat $CATALINA_PID`"
log_failure_msg "Failed to stop $NAME (pid $PID)"
exit 1
fi
rm -f "$CATALINA_PID"
rm -rf "$JVM_TMP"
else
log_progress_msg "(not running)"
fi
log_end_msg 0
set -e
;;
status)
set +e
start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null 2>&1
if [ "$?" = "0" ]; then
if [ -f "$CATALINA_PID" ]; then
log_success_msg "$DESC is not running, but pid file exists."
exit 1
else
log_success_msg "$DESC is not running."
exit 3
fi
else
log_success_msg "$DESC is running with pid `cat $CATALINA_PID`"
fi
set -e
;;
restart|force-reload)
if [ -f "$CATALINA_PID" ]; then
$0 stop
sleep 1
fi
$0 start
;;
try-restart)
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
$0 start
fi
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 1
;;
esac
exit 0
Centos7,Ubuntu14.04 Test by puppet automation? framework.
*Todo: separation of env variables to other file.pp
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat init.pp
class tomcat8 {
include tomcat8::account_add
$instance_owner = "tomcat8"
$instance_group = "tomcat8"
$java_opts = "-Djava.awt.headless=true -Xmx128M -XX:+UseConcMarkSweepGC"
#$java_opts = "-Dfile.encoding=UTF-8 -Dnet.sf.ehcache.skipUpdateCheck=true -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+UseParNewGC -XX:MaxPermSize=128m -Xms512m -Xmx512m"
$catalina_home = "/usr/local/tomcat8"
$catalina_base = "/usr/local/tomcat8"
$catalina_pid= "/usr/local/tomcat8/tomcat8.pid"
$java_security_manager = "no"
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
#java install
class { 'java': }
$java_home = "/usr/local/java"
$instance_name = "centos7-tomcat8"
#In case of new config as in tomcat8
include tomcat8::centos7_config
# do something RHEL specific
# execute 'yum update'
#exec { 'yum-update':
# command => '/bin/yum -y update'
#}
include tomcat8::get_tomcat
#running service
exec { 'tomcat8-start':
path => ['/bin','/usr/bin','/usr/sbin','/sbin'],
command => 'systemctl daemon-reload && systemctl start tomcat8 && systemctl enable tomcat8',
}
}
'ubuntu': {
#java install
class { 'java': }
#In case of new config as in tomcat8
include tomcat8::ubuntu_config
#tomcat version and compressed file
$java_home = "/usr/lib/jvm/java-7-oracle"
$default_file = "/etc/default/tomcat8"
$instance_name = "ubuntu-trusty-tomcat8"
include tomcat8::get_tomcat
# running tomcat8
service { 'tomcat8':
ensure => running,
}
}
default: {
# ...
}
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat get_tomcat.pp
class tomcat8::get_tomcat {
$TOMCAT="apache-tomcat"
$TOMCAT_DIR="tomcat-8"
$TOMCAT_VERSION="8.0.21"
$COMP=".tar.gz"
$INSTALL_DIR="/usr/local/tomcat8"
$POLICY_DIR="$INSTALL_DIR/conf/policy.d"
$instance_owner = "tomcat8"
$instance_group = "tomcat8"
exec { 'wget-tomcat':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
#using mirror
#command => "wget http://mirrors.advancedhosters.com/apache/tomcat/$TOMCAT_DIR/v$TOMCAT_VERSION/bin/$TOMCAT-$TOMCAT_VERSION$COMP",
#using local web server
command => "wget http://10.0.0.100/$TOMCAT-$TOMCAT_VERSION$COMP && tar xvzf $TOMCAT-$TOMCAT_VERSION$COMP",
unless => "ls /tmp/$TOMCAT-$TOMCAT_VERSION",
}
exec { 'tomcat-install':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
command => "mv $TOMCAT-$TOMCAT_VERSION $INSTALL_DIR && mkdir $POLICY_DIR && chown -R $instance_owner:$instance_group $INSTALL_DIR && chmod 0755 $INSTALL_DIR/conf && chown -R root:root $INSTALL_DIR/conf && chown -R root:$instance_group $INSTALL_DIR/conf/* && chmod 644 $INSTALL_DIR/conf/* && chmod 0755 $POLICY_DIR",
unless => "ls $INSTALL_DIR",
require => Exec['wget-tomcat'],
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat centos7_config.pp
class tomcat8::centos7_config {
file { "/etc/systemd/system/tomcat8.service":
ensure => present,
owner => 'root',
group => 'root',
mode => 0700,
#enable => true,
content => template('tomcat8/centos7-tomcat8.erb'),
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat account_add.pp
class tomcat8::account_add {
user { "tomcat8":
comment => "tomcat8user",
home => "/usr/local/tomcat8",
managehome => "false",
shell => "/bin/false",
uid => 109,
gid => 118,
}
group { "tomcat8":
gid => 118,
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat ubuntu_config.pp
class tomcat8::ubuntu_config {
file { "/etc/init.d/tomcat8":
ensure => present,
owner => 'root',
group => 'root',
mode => 0755,
content => template('tomcat8/ubuntu-tomcat8.erb'),
}
file { "/etc/default/tomcat8":
ensure => present,
owner => 'root',
group => 'root',
mode => 0640,
content => template('tomcat8/ubuntu-default-tomcat8.erb'),
}
}
root@puppet:/etc/puppet/modules/tomcat8# cat templates/centos7-tomcat8.erb
[Unit]
Description=Tomcat8
After=network.target
[Service]
Type=forking
User=<%= @instance_owner %>
Group=<%= @instance_group %>
Environment=CATALINA_PID=<%= @catalina_pid %>
Environment=JAVA_HOME=<%= @java_home %>
Environment=TOMCAT_JAVA_HOME=<%= @java_home %>
Environment=CATALINA_HOME=<%= @catalina_home %>
Environment=CATALINA_BASE=<%= @catalina_base %>
Environment=CATALINA_OPTS=
Environment="JAVA_OPTS=<%= @java_opts %>"
ExecStart=<%= @catalina_home %>/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID
[Install]
WantedBy=multi-user.target
root@puppet:/etc/puppet/modules/tomcat8# cat templates/ubuntu-default-tomcat8.erb
# File Managed by Puppet
# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat7.
TOMCAT8_USER=<%= @instance_owner %>
# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat7.
TOMCAT8_GROUP=<%= @instance_group %>
# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
<% if @java_home != '' -%>
JAVA_HOME=<%= @java_home %>
<% end -%>
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
<% if @java_opts != '' -%>
JAVA_OPTS="<%= @java_opts %>"
<% end -%>
#<% if @catalina_opts != '' -%>
#CATALINA_OPTS="<%= @catalina_opts %>"
#<% end -%>
# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=javac
# Use the Java security manager? (yes/no, default: no)
#TOMCAT8_SECURITY=no
# Number of days to keep logfiles in /var/log/tomcat7. Default is 14 days.
#LOGFILE_DAYS=14
# Location of the JVM temporary directory
# WARNING: This directory will be destroyed and recreated at every startup !
#JVM_TMP=/tmp/tomcat7-temp
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no
root@puppet:/etc/puppet/modules/tomcat8# cat templates/ubuntu-default-tomcat8.erb
# File Managed by Puppet
# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat7.
TOMCAT8_USER=<%= @instance_owner %>
# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat7.
TOMCAT8_GROUP=<%= @instance_group %>
# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
<% if @java_home != '' -%>
JAVA_HOME=<%= @java_home %>
<% end -%>
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
<% if @java_opts != '' -%>
JAVA_OPTS="<%= @java_opts %>"
<% end -%>
#<% if @catalina_opts != '' -%>
#CATALINA_OPTS="<%= @catalina_opts %>"
#<% end -%>
# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=javac
# Use the Java security manager? (yes/no, default: no)
#TOMCAT8_SECURITY=no
# Number of days to keep logfiles in /var/log/tomcat7. Default is 14 days.
#LOGFILE_DAYS=14
# Location of the JVM temporary directory
# WARNING: This directory will be destroyed and recreated at every startup !
#JVM_TMP=/tmp/tomcat7-temp
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no
root@puppet:/etc/puppet/modules/tomcat8# cat templates/ubuntu-
ubuntu-default-tomcat8.erb ubuntu-tomcat8.erb
root@puppet:/etc/puppet/modules/tomcat8# cat templates/ubuntu-tomcat8.erb
#!/bin/sh
# File Managed by Puppet
#
# Modification of https://raw.githubusercontent.com/example42/puppet-tomcat/master/templates/instance/init7-Debian.erb
# /etc/init.d/tomcat8 -- startup script for the Tomcat 8 servlet engine
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Tomcat by Stefan Gybas <sgybas@debian.org>.
# Modified for Tomcat6 by Thierry Carrez <thierry.carrez@ubuntu.com>.
# Modified for Tomcat7 by Ernesto Hernandez-Novich <emhn@itverx.com.ve>.
# Modified for Tomcat8 by OhYoungJooung <wnapdlf05@gmail.com>.
# Additional improvements by Jason Brittain <jason.brittain@mulesoft.com>.
#
### BEGIN INIT INFO
# Provides: tomcat8-<%= @instance_name %>
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Tomcat.
# Description: Start the Tomcat servlet engine.
### END INIT INFO
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=`basename $0`
DESC="Tomcat8 servlet engine"
DEFAULT=/etc/default/$NAME
JVM_TMP=/tmp/tomcat8-$NAME-tmp
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
# Make sure tomcat is started with system locale
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG
fi
. /lib/lsb/init-functions
if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi
# The following variables can be overwritten in $DEFAULT
# Run Tomcat 8 as this user ID and group ID
TOMCAT8_USER=<%= @instance_owner %>
TOMCAT8_GROUP=<%= @instance_group %>
# this is a work-around until there is a suitable runtime replacement
# for dpkg-architecture for arch:all packages
# this function sets the variable OPENJDKS
find_openjdks()
{
for jvmdir in /usr/lib/jvm/java-7-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ]
then
OPENJDKS=$jvmdir
fi
done
for jvmdir in /usr/lib/jvm/java-6-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ]
then
OPENJDKS="${OPENJDKS} ${jvmdir}"
fi
done
}
OPENJDKS=""
find_openjdks
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT)
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-7-oracle"
# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
# Directory where the Tomcat 6 binary distribution resides
CATALINA_HOME=<%= @catalina_home %>
# Directory for per-instance configuration files and webapps
CATALINA_BASE=<%= @catalina_base %>
# Use the Java security manager? (yes/no)
TOMCAT8_SECURITY=<%= @java_security_manager %>
# Default Java options
# Set java.awt.headless=true if JAVA_OPTS is not set so the
# Xalan XSL transformer can work without X11 display on JDK 1.4+
# It also looks like the default heap size of 64M is not enough for most cases
# so the maximum heap size is set to 128M
if [ -z "$JAVA_OPTS" ]; then
JAVA_OPTS="<%= @java_opts %>"
fi
# End of variables that can be overwritten in $DEFAULT
# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. <%= $default_File %>
fi
if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then
log_failure_msg "$NAME is not installed"
exit 1
fi
POLICY_CACHE="$CATALINA_BASE/work/catalina.policy"
if [ -z "$CATALINA_TMPDIR" ]; then
CATALINA_TMPDIR="$JVM_TMP"
fi
# Set the JSP compiler if set in the tomcat8.default file
if [ -n "$JSP_COMPILER" ]; then
JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\""
fi
SECURITY=""
if [ "$TOMCAT8_SECURITY" = "yes" ]; then
SECURITY="-security"
fi
# Define other required variables
CATALINA_PID="/var/run/$NAME.pid"
CATALINA_SH="$CATALINA_HOME/bin/catalina.sh"
# Look for Java Secure Sockets Extension (JSSE) JARs
if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then
JSSE_HOME="${JAVA_HOME}/jre/"
fi
catalina_sh() {
# Escape any double quotes in the value of JAVA_OPTS
JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')"
AUTHBIND_COMMAND=""
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c "
fi
# Define the command to run Tomcat's catalina.sh as a daemon
# set -a tells sh to export assigned variables to spawned shells.
TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \
CATALINA_HOME=\"$CATALINA_HOME\"; \
CATALINA_BASE=\"$CATALINA_BASE\"; \
JAVA_OPTS=\"$JAVA_OPTS\"; \
CATALINA_PID=\"$CATALINA_PID\"; \
CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \
LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \
cd \"$CATALINA_BASE\"; \
\"$CATALINA_SH\" $@"
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
TOMCAT_SH="'$TOMCAT_SH'"
fi
# Run the catalina.sh script as a daemon
set +e
touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
chown $TOMCAT8_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
start-stop-daemon --start -b -u "$TOMCAT8_USER" -g "$TOMCAT8_GROUP" \
-c "$TOMCAT8_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \
-x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
status="$?"
set +a -e
return $status
}
case "$1" in
start)
if [ -z "$JAVA_HOME" ]; then
log_failure_msg "no JDK found - please set JAVA_HOME"
exit 1
fi
if [ ! -d "$CATALINA_BASE/conf" ]; then
log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
exit 1
fi
log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
# Regenerate POLICY_CACHE file
umask 022
echo "// AUTO-GENERATED FILE from /etc/tomcat8/policy.d/" \
> "$POLICY_CACHE"
echo "" >> "$POLICY_CACHE"
if [ $(ls -1 $CATALINA_BASE/conf/policy.d/ | grep ".policy$" | wc -l) -ne 0 ]; then
cat $CATALINA_BASE/conf/policy.d/*.policy \
>> "$POLICY_CACHE"
fi
# Remove / recreate JVM_TMP directory
rm -rf "$JVM_TMP"
mkdir -p "$JVM_TMP" || {
log_failure_msg "could not create JVM temporary directory"
exit 1
}
chown $TOMCAT8_USER "$JVM_TMP"
catalina_sh start $SECURITY
sleep 5
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
if [ -f "$CATALINA_PID" ]; then
rm -f "$CATALINA_PID"
fi
log_end_msg 1
else
log_end_msg 0
fi
else
log_progress_msg "(already running)"
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
set +e
if [ -f "$CATALINA_PID" ]; then
start-stop-daemon --stop --pidfile "$CATALINA_PID" \
--user "$TOMCAT8_USER" \
--retry=TERM/20/KILL/5 >/dev/null
if [ $? -eq 1 ]; then
log_progress_msg "$DESC is not running but pid file exists, cleaning up"
elif [ $? -eq 3 ]; then
PID="`cat $CATALINA_PID`"
log_failure_msg "Failed to stop $NAME (pid $PID)"
exit 1
fi
rm -f "$CATALINA_PID"
rm -rf "$JVM_TMP"
else
log_progress_msg "(not running)"
fi
log_end_msg 0
set -e
;;
status)
set +e
start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null 2>&1
if [ "$?" = "0" ]; then
if [ -f "$CATALINA_PID" ]; then
log_success_msg "$DESC is not running, but pid file exists."
exit 1
else
log_success_msg "$DESC is not running."
exit 3
fi
else
log_success_msg "$DESC is running with pid `cat $CATALINA_PID`"
fi
set -e
;;
restart|force-reload)
if [ -f "$CATALINA_PID" ]; then
$0 stop
sleep 1
fi
$0 start
;;
try-restart)
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
$0 start
fi
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 1
;;
esac
exit 0
Sunday, April 12, 2015
Puppet::java_oracle_centos configuration
#puppet hostname is puppet
#centos7 hostname is ct7
#Goal: installing oracle java 7 from tar.gz to centos7 distro
#Using local web server
root@puppet:/etc/puppet/modules/java/manifests# cat oracle_jdk7.pp
class java::oracle_jdk7 {
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
$java_install_path="/usr/local/java"
$jdk_file="jdk-7u75-linux-x64.tar.gz"
$jdk_dir="jdk1.7.0_75"
$local_web="http://10.0.0.100"
# do something CentOS specific
# execute 'yum update'
exec { 'yum-update':
command => '/bin/yum -y update',
}
exec { 'wget-install':
path => ['/bin','/usr/bin'],
command => '/bin/yum -y install wget',
unless => 'ls /usr/bin/wget',
require => Exec['yum-update'],
}
exec { 'jdk7-get-untar':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
#when using oracle web site
#command => "wget --no-cookies --no-check-certificate --header \"Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie\" \"http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.tar.gz\" ",
#when using local web
#command => "wget $local_web/$jdk_file",
unless => "ls /tmp/$jdk_file",
timeout => 0,
require => Exec['wget-install'],
}
exec { 'jdk7-install-to-path':
cwd => '/tmp',
path => ['/bin','/usr/bin'],
command => "tar xvzf $jdk_file && mv $jdk_dir $java_install_path",
unless => "ls $java_install_path/bin",
require => Exec['jdk7-get-untar'],
}
include java::centos_config
}
'ubuntu': {
#On ubuntu use ppa
class { 'apt': }
# Add ppa
apt::ppa { 'ppa:webupd8team/java':} ->
# Prepare response file
file { "/tmp/oracle-java7-installer.preseed":
source => 'puppet:///modules/java/java.response',
mode => 600,
backup => false,
} ->
# Install java
package { "oracle-java7-installer":
ensure => "installed",
responsefile => '/tmp/oracle-java7-installer.preseed'
} ->
package { "oracle-java7-set-default": ensure => "installed" }
}
}
}
root@puppet:/etc/puppet/modules/java/manifests# cat centos_config.pp
class java::centos_config {
file { "/etc/profile":
ensure => present,
group => 'root',
owner => 'root',
mode => 0644,
source => "puppet:///modules/java/java.oracle.centos.profile",
}
}
#profile java path insert
#root@puppet:/etc/puppet/modules/java/manifests# cat ../files/java.oracle.centos.profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`id -u`
UID=`id -ru`
fi
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
export PATH=/usr/local/java/bin:$PATH
root@puppet:/etc/puppet/modules/java/manifests# cat init.pp
class java {
include java::oracle_jdk7
}
#site.pp
root@puppet:/etc/puppet/modules/java/manifests# cat /etc/puppet/manifests/site.pp
node default { include ssh }
node 'ct7' {
include java
}
#Test on centos7(ct7) node
[root@ct7 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ct7
Info: Applying configuration version '1428899877'
Notice: /Stage[main]/Java::Oracle_jdk7/Exec[jdk7-install-to-path]/returns: executed successfully
Notice: /Stage[main]/Java::Centos_config/File[/etc/profile]/content:
--- /etc/profile 2015-04-13 04:37:47.095816707 +0000
+++ /tmp/puppet-file20150413-5363-w912dg 2015-04-13 04:38:00.971816547 +0000
@@ -74,3 +74,4 @@
unset i
unset -f pathmunge
+export PATH=/usr/local/java/bin:$PATH
Info: Computing checksum on file /etc/profile
Info: FileBucket got a duplicate file {md5}b3fb9b49834801ac9532447053dab36f
Info: /Stage[main]/Java::Centos_config/File[/etc/profile]: Filebucketed /etc/profile to puppet with sum b3fb9b49834801ac9532447053dab36f
Notice: /Stage[main]/Java::Centos_config/File[/etc/profile]/content: content changed '{md5}b3fb9b49834801ac9532447053dab36f' to '{md5}4e76aeb186c5c0f9c841df324f24b877'
Notice: Finished catalog run in 3.80 seconds
#centos7 hostname is ct7
#Goal: installing oracle java 7 from tar.gz to centos7 distro
#Using local web server
root@puppet:/etc/puppet/modules/java/manifests# cat oracle_jdk7.pp
class java::oracle_jdk7 {
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
$java_install_path="/usr/local/java"
$jdk_file="jdk-7u75-linux-x64.tar.gz"
$jdk_dir="jdk1.7.0_75"
$local_web="http://10.0.0.100"
# do something CentOS specific
# execute 'yum update'
exec { 'yum-update':
command => '/bin/yum -y update',
}
exec { 'wget-install':
path => ['/bin','/usr/bin'],
command => '/bin/yum -y install wget',
unless => 'ls /usr/bin/wget',
require => Exec['yum-update'],
}
exec { 'jdk7-get-untar':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
#when using oracle web site
#command => "wget --no-cookies --no-check-certificate --header \"Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie\" \"http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.tar.gz\" ",
#when using local web
#command => "wget $local_web/$jdk_file",
unless => "ls /tmp/$jdk_file",
timeout => 0,
require => Exec['wget-install'],
}
exec { 'jdk7-install-to-path':
cwd => '/tmp',
path => ['/bin','/usr/bin'],
command => "tar xvzf $jdk_file && mv $jdk_dir $java_install_path",
unless => "ls $java_install_path/bin",
require => Exec['jdk7-get-untar'],
}
include java::centos_config
}
'ubuntu': {
#On ubuntu use ppa
class { 'apt': }
# Add ppa
apt::ppa { 'ppa:webupd8team/java':} ->
# Prepare response file
file { "/tmp/oracle-java7-installer.preseed":
source => 'puppet:///modules/java/java.response',
mode => 600,
backup => false,
} ->
# Install java
package { "oracle-java7-installer":
ensure => "installed",
responsefile => '/tmp/oracle-java7-installer.preseed'
} ->
package { "oracle-java7-set-default": ensure => "installed" }
}
}
}
root@puppet:/etc/puppet/modules/java/manifests# cat centos_config.pp
class java::centos_config {
file { "/etc/profile":
ensure => present,
group => 'root',
owner => 'root',
mode => 0644,
source => "puppet:///modules/java/java.oracle.centos.profile",
}
}
#profile java path insert
#root@puppet:/etc/puppet/modules/java/manifests# cat ../files/java.oracle.centos.profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`id -u`
UID=`id -ru`
fi
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
export PATH=/usr/local/java/bin:$PATH
root@puppet:/etc/puppet/modules/java/manifests# cat init.pp
class java {
include java::oracle_jdk7
}
#site.pp
root@puppet:/etc/puppet/modules/java/manifests# cat /etc/puppet/manifests/site.pp
node default { include ssh }
node 'ct7' {
include java
}
#Test on centos7(ct7) node
[root@ct7 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ct7
Info: Applying configuration version '1428899877'
Notice: /Stage[main]/Java::Oracle_jdk7/Exec[jdk7-install-to-path]/returns: executed successfully
Notice: /Stage[main]/Java::Centos_config/File[/etc/profile]/content:
--- /etc/profile 2015-04-13 04:37:47.095816707 +0000
+++ /tmp/puppet-file20150413-5363-w912dg 2015-04-13 04:38:00.971816547 +0000
@@ -74,3 +74,4 @@
unset i
unset -f pathmunge
+export PATH=/usr/local/java/bin:$PATH
Info: Computing checksum on file /etc/profile
Info: FileBucket got a duplicate file {md5}b3fb9b49834801ac9532447053dab36f
Info: /Stage[main]/Java::Centos_config/File[/etc/profile]: Filebucketed /etc/profile to puppet with sum b3fb9b49834801ac9532447053dab36f
Notice: /Stage[main]/Java::Centos_config/File[/etc/profile]/content: content changed '{md5}b3fb9b49834801ac9532447053dab36f' to '{md5}4e76aeb186c5c0f9c841df324f24b877'
Notice: Finished catalog run in 3.80 seconds
Installation tomcat8 on ubuntu trusty14.04 using puppet
*Goal: Installation tomcat8 on ubuntu trusty14.04.
*Target node: ts(hostname,test server)
* Vagrant env
*Puppet master hostname: puppet
root@puppet:/etc/puppet/modules/tomcat8# cd manifests/
#init.pp
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat init.pp
class tomcat8 {
include tomcat8::account_add
$instance_name = "ubuntu-trusty-tomcat8"
$instance_owner = "tomcat8"
$instance_group = "tomcat8"
$java_home = "/usr/lib/jvm/java-7-oracle"
$java_opts = "-Djava.awt.headless=true -Xmx128M -XX:+UseConcMarkSweepGC"
$catalina_home = "/usr/local/tomcat8"
$catalina_base = "/usr/local/tomcat8"
$java_security_manager = "no"
$default_file = "/etc/default/tomcat8"
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
include tomcat8::config
# do something RHEL specific
# execute 'yum update'
exec { 'yum-update':
command => '/bin/yum -y update'
}
#running service
service { 'tomcat8':
ensure => running,
}
}
'ubuntu': {
#http://wnapdlf.blogspot.jp/2015/04/puppet-oracle-java7-installation.html
#java install
class { 'java': }
#In case of new config as in tomcat8
include tomcat8::ubuntu_config
#tomcat version and compressed file
$TOMCAT="apache-tomcat"
$TOMCAT_DIR="tomcat-8"
$TOMCAT_VERSION="8.0.21"
$COMP=".tar.gz"
$INSTALL_DIR="/usr/local/tomcat8"
$POLICY_DIR="$INSTALL_DIR/conf/policy.d"
#tomcat binary download
exec { 'wget-tomcat':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
command => "wget http://mirrors.advancedhosters.com/apache/tomcat/$TOMCAT_DIR/v$TOMCAT_VERSION/bin/$TOMCAT-$TOMCAT_VERSION$COMP",
unless => "ls /tmp/$TOMCAT-$TOMCAT_VERSION$COMP",
}
exec { 'uncompress-tomcat':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
command => "tar xvzf $TOMCAT-$TOMCAT_VERSION$COMP && mv $TOMCAT-$TOMCAT_VERSION $INSTALL_DIR",
unless => "ls /tmp/$TOMCAT-$TOMCAT_VERSION",
require => Exec['wget-tomcat'],
}
exec { 'policy-dir':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
command => "mkdir $POLICY_DIR && chown -R $instance_owner:$instance_group $INSTALL_DIR && chmod 0755 $INSTALL_DIR/conf && chown -R root:root $INSTALL_DIR/conf && chown -R root:$instance_group $INSTALL_DIR/conf/* && chmod 644 $INSTALL_DIR/conf/* && chmod 0755 $POLICY_DIR",
require => Exec['uncompress-tomcat'],
}
# running tomcat8
service { 'tomcat8':
ensure => running,
require => Exec['policy-dir'],
}
}
default: {
# ...to do: installing tomcat8 on centos7
}
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat account_add.pp
class tomcat8::account_add {
user { "tomcat8":
comment => "tomcat8user",
home => "/usr/local/tomcat8",
managehome => "false",
shell => "/bin/false",
uid => 109,
gid => 118,
}
group { "tomcat8":
gid => 118,
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat ubuntu_config.pp
class tomcat8::ubuntu_config {
file { "/etc/init.d/tomcat8":
ensure => present,
owner => 'root',
group => 'root',
mode => 0755,
content => template('tomcat8/ubuntu-tomcat8.erb'),
}
file { "/etc/default/tomcat8":
ensure => present,
owner => 'root',
group => 'root',
mode => 0640,
content => template('tomcat8/ubuntu-default-tomcat8.erb'),
}
}
root@puppet:/etc/puppet/modules/tomcat8/templates# cat ubuntu-tomcat8.erb
#!/bin/sh
# File Managed by Puppet
#
# Modification of https://raw.githubusercontent.com/example42/puppet-tomcat/master/templates/instance/init7-Debian.erb
# /etc/init.d/tomcat8 -- startup script for the Tomcat 8 servlet engine
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Tomcat by Stefan Gybas <sgybas@debian.org>.
# Modified for Tomcat6 by Thierry Carrez <thierry.carrez@ubuntu.com>.
# Modified for Tomcat7 by Ernesto Hernandez-Novich <emhn@itverx.com.ve>.
# Modified for Tomcat8 by OhYoungJooung <wnapdlf05@gmail.com>.
# Additional improvements by Jason Brittain <jason.brittain@mulesoft.com>.
#
### BEGIN INIT INFO
# Provides: tomcat8-<%= @instance_name %>
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Tomcat.
# Description: Start the Tomcat servlet engine.
### END INIT INFO
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=`basename $0`
DESC="Tomcat8 servlet engine"
DEFAULT=/etc/default/$NAME
JVM_TMP=/tmp/tomcat8-$NAME-tmp
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
# Make sure tomcat is started with system locale
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG
fi
. /lib/lsb/init-functions
if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi
# The following variables can be overwritten in $DEFAULT
# Run Tomcat 8 as this user ID and group ID
TOMCAT8_USER=<%= @instance_owner %>
TOMCAT8_GROUP=<%= @instance_group %>
# this is a work-around until there is a suitable runtime replacement
# for dpkg-architecture for arch:all packages
# this function sets the variable OPENJDKS
find_openjdks()
{
for jvmdir in /usr/lib/jvm/java-7-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ]
then
OPENJDKS=$jvmdir
fi
done
for jvmdir in /usr/lib/jvm/java-6-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ]
then
OPENJDKS="${OPENJDKS} ${jvmdir}"
fi
done
}
OPENJDKS=""
find_openjdks
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT)
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-7-oracle"
# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
# Directory where the Tomcat 6 binary distribution resides
CATALINA_HOME=<%= @catalina_home %>
# Directory for per-instance configuration files and webapps
CATALINA_BASE=<%= @catalina_base %>
# Use the Java security manager? (yes/no)
TOMCAT8_SECURITY=<%= @java_security_manager %>
# Default Java options
# Set java.awt.headless=true if JAVA_OPTS is not set so the
# Xalan XSL transformer can work without X11 display on JDK 1.4+
# It also looks like the default heap size of 64M is not enough for most cases
# so the maximum heap size is set to 128M
if [ -z "$JAVA_OPTS" ]; then
JAVA_OPTS="<%= @java_opts %>"
fi
# End of variables that can be overwritten in $DEFAULT
# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. <%= $default_File %>
fi
if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then
log_failure_msg "$NAME is not installed"
exit 1
fi
POLICY_CACHE="$CATALINA_BASE/work/catalina.policy"
if [ -z "$CATALINA_TMPDIR" ]; then
CATALINA_TMPDIR="$JVM_TMP"
fi
# Set the JSP compiler if set in the tomcat8.default file
if [ -n "$JSP_COMPILER" ]; then
JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\""
fi
SECURITY=""
if [ "$TOMCAT8_SECURITY" = "yes" ]; then
SECURITY="-security"
fi
# Define other required variables
CATALINA_PID="/var/run/$NAME.pid"
CATALINA_SH="$CATALINA_HOME/bin/catalina.sh"
# Look for Java Secure Sockets Extension (JSSE) JARs
if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then
JSSE_HOME="${JAVA_HOME}/jre/"
fi
catalina_sh() {
# Escape any double quotes in the value of JAVA_OPTS
JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')"
AUTHBIND_COMMAND=""
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c "
fi
# Define the command to run Tomcat's catalina.sh as a daemon
# set -a tells sh to export assigned variables to spawned shells.
TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \
CATALINA_HOME=\"$CATALINA_HOME\"; \
CATALINA_BASE=\"$CATALINA_BASE\"; \
JAVA_OPTS=\"$JAVA_OPTS\"; \
CATALINA_PID=\"$CATALINA_PID\"; \
CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \
LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \
cd \"$CATALINA_BASE\"; \
\"$CATALINA_SH\" $@"
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
TOMCAT_SH="'$TOMCAT_SH'"
fi
# Run the catalina.sh script as a daemon
set +e
touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
chown $TOMCAT8_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
start-stop-daemon --start -b -u "$TOMCAT8_USER" -g "$TOMCAT8_GROUP" \
-c "$TOMCAT8_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \
-x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
status="$?"
set +a -e
return $status
}
case "$1" in
start)
if [ -z "$JAVA_HOME" ]; then
log_failure_msg "no JDK found - please set JAVA_HOME"
exit 1
fi
if [ ! -d "$CATALINA_BASE/conf" ]; then
log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
exit 1
fi
log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
# Regenerate POLICY_CACHE file
umask 022
echo "// AUTO-GENERATED FILE from /etc/tomcat8/policy.d/" \
> "$POLICY_CACHE"
echo "" >> "$POLICY_CACHE"
if [ $(ls -1 $CATALINA_BASE/conf/policy.d/ | grep ".policy$" | wc -l) -ne 0 ]; then
cat $CATALINA_BASE/conf/policy.d/*.policy \
>> "$POLICY_CACHE"
fi
# Remove / recreate JVM_TMP directory
rm -rf "$JVM_TMP"
mkdir -p "$JVM_TMP" || {
log_failure_msg "could not create JVM temporary directory"
exit 1
}
chown $TOMCAT8_USER "$JVM_TMP"
catalina_sh start $SECURITY
sleep 5
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
if [ -f "$CATALINA_PID" ]; then
rm -f "$CATALINA_PID"
fi
log_end_msg 1
else
log_end_msg 0
fi
else
log_progress_msg "(already running)"
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
set +e
if [ -f "$CATALINA_PID" ]; then
start-stop-daemon --stop --pidfile "$CATALINA_PID" \
--user "$TOMCAT8_USER" \
--retry=TERM/20/KILL/5 >/dev/null
if [ $? -eq 1 ]; then
log_progress_msg "$DESC is not running but pid file exists, cleaning up"
elif [ $? -eq 3 ]; then
PID="`cat $CATALINA_PID`"
log_failure_msg "Failed to stop $NAME (pid $PID)"
exit 1
fi
rm -f "$CATALINA_PID"
rm -rf "$JVM_TMP"
else
log_progress_msg "(not running)"
fi
log_end_msg 0
set -e
;;
status)
set +e
start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null 2>&1
if [ "$?" = "0" ]; then
if [ -f "$CATALINA_PID" ]; then
log_success_msg "$DESC is not running, but pid file exists."
exit 1
else
log_success_msg "$DESC is not running."
exit 3
fi
else
log_success_msg "$DESC is running with pid `cat $CATALINA_PID`"
fi
set -e
;;
restart|force-reload)
if [ -f "$CATALINA_PID" ]; then
$0 stop
sleep 1
fi
$0 start
;;
try-restart)
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
$0 start
fi
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 1
;;
esac
exit 0
root@puppet:/etc/puppet/modules/tomcat8/templates# cat ubuntu-default-tomcat8.erb
# File Managed by Puppet
# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat7.
TOMCAT8_USER=<%= @instance_owner %>
# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat7.
TOMCAT8_GROUP=<%= @instance_group %>
# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
<% if @java_home != '' -%>
JAVA_HOME=<%= @java_home %>
<% end -%>
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
<% if @java_opts != '' -%>
JAVA_OPTS="<%= @java_opts %>"
<% end -%>
#<% if @catalina_opts != '' -%>
#CATALINA_OPTS="<%= @catalina_opts %>"
#<% end -%>
# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=javac
# Use the Java security manager? (yes/no, default: no)
#TOMCAT8_SECURITY=no
# Number of days to keep logfiles in /var/log/tomcat7. Default is 14 days.
#LOGFILE_DAYS=14
# Location of the JVM temporary directory
# WARNING: This directory will be destroyed and recreated at every startup !
#JVM_TMP=/tmp/tomcat7-temp
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no
root@ts:~# puppet agent --test
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ts
Info: Applying configuration version '1428831538'
Notice: /Stage[main]/Tomcat8::Ubuntu_config/File[/etc/init.d/tomcat8]/ensure: created
Notice: /Stage[main]/Tomcat8::Ubuntu_config/File[/etc/default/tomcat8]/ensure: created
Notice: /Stage[main]/Tomcat8/Exec[uncompress-tomcat]/returns: executed successfully
Notice: /Stage[main]/Tomcat8/Exec[policy-dir]/returns: executed successfully
Notice: /Stage[main]/Tomcat8/Service[tomcat8]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Tomcat8/Service[tomcat8]: Unscheduling refresh on Service[tomcat8]
Notice: Finished catalog run in 5.56 seconds
root@ts:~# ps -ef | grep tomcat8
root 16153 5255 0 18:36 pts/0 00:00:00 tail -f /usr/local/tomcat8/logs/catalina.out
tomcat8 17042 1 23 18:40 ? 00:00:02 /usr/lib/jvm/java-7-oracle/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx128M -XX:+UseConcMarkSweepGC -Djava.endorsed.dirs=/usr/local/tomcat8/endorsed -classpath /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8 -Dcatalina.home=/usr/local/tomcat8 -Djava.io.tmpdir=/tmp/tomcat8-tomcat8-tmp org.apache.catalina.startup.Bootstrap start
*Target node: ts(hostname,test server)
* Vagrant env
*Puppet master hostname: puppet
root@puppet:/etc/puppet/modules/tomcat8# cd manifests/
#init.pp
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat init.pp
class tomcat8 {
include tomcat8::account_add
$instance_name = "ubuntu-trusty-tomcat8"
$instance_owner = "tomcat8"
$instance_group = "tomcat8"
$java_home = "/usr/lib/jvm/java-7-oracle"
$java_opts = "-Djava.awt.headless=true -Xmx128M -XX:+UseConcMarkSweepGC"
$catalina_home = "/usr/local/tomcat8"
$catalina_base = "/usr/local/tomcat8"
$java_security_manager = "no"
$default_file = "/etc/default/tomcat8"
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
include tomcat8::config
# do something RHEL specific
# execute 'yum update'
exec { 'yum-update':
command => '/bin/yum -y update'
}
#running service
service { 'tomcat8':
ensure => running,
}
}
'ubuntu': {
#http://wnapdlf.blogspot.jp/2015/04/puppet-oracle-java7-installation.html
#java install
class { 'java': }
#In case of new config as in tomcat8
include tomcat8::ubuntu_config
#tomcat version and compressed file
$TOMCAT="apache-tomcat"
$TOMCAT_DIR="tomcat-8"
$TOMCAT_VERSION="8.0.21"
$COMP=".tar.gz"
$INSTALL_DIR="/usr/local/tomcat8"
$POLICY_DIR="$INSTALL_DIR/conf/policy.d"
#tomcat binary download
exec { 'wget-tomcat':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
command => "wget http://mirrors.advancedhosters.com/apache/tomcat/$TOMCAT_DIR/v$TOMCAT_VERSION/bin/$TOMCAT-$TOMCAT_VERSION$COMP",
unless => "ls /tmp/$TOMCAT-$TOMCAT_VERSION$COMP",
}
exec { 'uncompress-tomcat':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
command => "tar xvzf $TOMCAT-$TOMCAT_VERSION$COMP && mv $TOMCAT-$TOMCAT_VERSION $INSTALL_DIR",
unless => "ls /tmp/$TOMCAT-$TOMCAT_VERSION",
require => Exec['wget-tomcat'],
}
exec { 'policy-dir':
path => ['/bin','/usr/bin'],
cwd => '/tmp',
command => "mkdir $POLICY_DIR && chown -R $instance_owner:$instance_group $INSTALL_DIR && chmod 0755 $INSTALL_DIR/conf && chown -R root:root $INSTALL_DIR/conf && chown -R root:$instance_group $INSTALL_DIR/conf/* && chmod 644 $INSTALL_DIR/conf/* && chmod 0755 $POLICY_DIR",
require => Exec['uncompress-tomcat'],
}
# running tomcat8
service { 'tomcat8':
ensure => running,
require => Exec['policy-dir'],
}
}
default: {
# ...to do: installing tomcat8 on centos7
}
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat account_add.pp
class tomcat8::account_add {
user { "tomcat8":
comment => "tomcat8user",
home => "/usr/local/tomcat8",
managehome => "false",
shell => "/bin/false",
uid => 109,
gid => 118,
}
group { "tomcat8":
gid => 118,
}
}
root@puppet:/etc/puppet/modules/tomcat8/manifests# cat ubuntu_config.pp
class tomcat8::ubuntu_config {
file { "/etc/init.d/tomcat8":
ensure => present,
owner => 'root',
group => 'root',
mode => 0755,
content => template('tomcat8/ubuntu-tomcat8.erb'),
}
file { "/etc/default/tomcat8":
ensure => present,
owner => 'root',
group => 'root',
mode => 0640,
content => template('tomcat8/ubuntu-default-tomcat8.erb'),
}
}
root@puppet:/etc/puppet/modules/tomcat8/templates# cat ubuntu-tomcat8.erb
#!/bin/sh
# File Managed by Puppet
#
# Modification of https://raw.githubusercontent.com/example42/puppet-tomcat/master/templates/instance/init7-Debian.erb
# /etc/init.d/tomcat8 -- startup script for the Tomcat 8 servlet engine
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for Tomcat by Stefan Gybas <sgybas@debian.org>.
# Modified for Tomcat6 by Thierry Carrez <thierry.carrez@ubuntu.com>.
# Modified for Tomcat7 by Ernesto Hernandez-Novich <emhn@itverx.com.ve>.
# Modified for Tomcat8 by OhYoungJooung <wnapdlf05@gmail.com>.
# Additional improvements by Jason Brittain <jason.brittain@mulesoft.com>.
#
### BEGIN INIT INFO
# Provides: tomcat8-<%= @instance_name %>
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Tomcat.
# Description: Start the Tomcat servlet engine.
### END INIT INFO
set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=`basename $0`
DESC="Tomcat8 servlet engine"
DEFAULT=/etc/default/$NAME
JVM_TMP=/tmp/tomcat8-$NAME-tmp
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
# Make sure tomcat is started with system locale
if [ -r /etc/default/locale ]; then
. /etc/default/locale
export LANG
fi
. /lib/lsb/init-functions
if [ -r /etc/default/rcS ]; then
. /etc/default/rcS
fi
# The following variables can be overwritten in $DEFAULT
# Run Tomcat 8 as this user ID and group ID
TOMCAT8_USER=<%= @instance_owner %>
TOMCAT8_GROUP=<%= @instance_group %>
# this is a work-around until there is a suitable runtime replacement
# for dpkg-architecture for arch:all packages
# this function sets the variable OPENJDKS
find_openjdks()
{
for jvmdir in /usr/lib/jvm/java-7-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ]
then
OPENJDKS=$jvmdir
fi
done
for jvmdir in /usr/lib/jvm/java-6-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ]
then
OPENJDKS="${OPENJDKS} ${jvmdir}"
fi
done
}
OPENJDKS=""
find_openjdks
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT)
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-7-oracle"
# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
# Directory where the Tomcat 6 binary distribution resides
CATALINA_HOME=<%= @catalina_home %>
# Directory for per-instance configuration files and webapps
CATALINA_BASE=<%= @catalina_base %>
# Use the Java security manager? (yes/no)
TOMCAT8_SECURITY=<%= @java_security_manager %>
# Default Java options
# Set java.awt.headless=true if JAVA_OPTS is not set so the
# Xalan XSL transformer can work without X11 display on JDK 1.4+
# It also looks like the default heap size of 64M is not enough for most cases
# so the maximum heap size is set to 128M
if [ -z "$JAVA_OPTS" ]; then
JAVA_OPTS="<%= @java_opts %>"
fi
# End of variables that can be overwritten in $DEFAULT
# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. <%= $default_File %>
fi
if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then
log_failure_msg "$NAME is not installed"
exit 1
fi
POLICY_CACHE="$CATALINA_BASE/work/catalina.policy"
if [ -z "$CATALINA_TMPDIR" ]; then
CATALINA_TMPDIR="$JVM_TMP"
fi
# Set the JSP compiler if set in the tomcat8.default file
if [ -n "$JSP_COMPILER" ]; then
JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\""
fi
SECURITY=""
if [ "$TOMCAT8_SECURITY" = "yes" ]; then
SECURITY="-security"
fi
# Define other required variables
CATALINA_PID="/var/run/$NAME.pid"
CATALINA_SH="$CATALINA_HOME/bin/catalina.sh"
# Look for Java Secure Sockets Extension (JSSE) JARs
if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then
JSSE_HOME="${JAVA_HOME}/jre/"
fi
catalina_sh() {
# Escape any double quotes in the value of JAVA_OPTS
JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')"
AUTHBIND_COMMAND=""
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c "
fi
# Define the command to run Tomcat's catalina.sh as a daemon
# set -a tells sh to export assigned variables to spawned shells.
TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \
CATALINA_HOME=\"$CATALINA_HOME\"; \
CATALINA_BASE=\"$CATALINA_BASE\"; \
JAVA_OPTS=\"$JAVA_OPTS\"; \
CATALINA_PID=\"$CATALINA_PID\"; \
CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \
LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \
cd \"$CATALINA_BASE\"; \
\"$CATALINA_SH\" $@"
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
TOMCAT_SH="'$TOMCAT_SH'"
fi
# Run the catalina.sh script as a daemon
set +e
touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
chown $TOMCAT8_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
start-stop-daemon --start -b -u "$TOMCAT8_USER" -g "$TOMCAT8_GROUP" \
-c "$TOMCAT8_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \
-x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
status="$?"
set +a -e
return $status
}
case "$1" in
start)
if [ -z "$JAVA_HOME" ]; then
log_failure_msg "no JDK found - please set JAVA_HOME"
exit 1
fi
if [ ! -d "$CATALINA_BASE/conf" ]; then
log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
exit 1
fi
log_daemon_msg "Starting $DESC" "$NAME"
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
# Regenerate POLICY_CACHE file
umask 022
echo "// AUTO-GENERATED FILE from /etc/tomcat8/policy.d/" \
> "$POLICY_CACHE"
echo "" >> "$POLICY_CACHE"
if [ $(ls -1 $CATALINA_BASE/conf/policy.d/ | grep ".policy$" | wc -l) -ne 0 ]; then
cat $CATALINA_BASE/conf/policy.d/*.policy \
>> "$POLICY_CACHE"
fi
# Remove / recreate JVM_TMP directory
rm -rf "$JVM_TMP"
mkdir -p "$JVM_TMP" || {
log_failure_msg "could not create JVM temporary directory"
exit 1
}
chown $TOMCAT8_USER "$JVM_TMP"
catalina_sh start $SECURITY
sleep 5
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
if [ -f "$CATALINA_PID" ]; then
rm -f "$CATALINA_PID"
fi
log_end_msg 1
else
log_end_msg 0
fi
else
log_progress_msg "(already running)"
log_end_msg 0
fi
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
set +e
if [ -f "$CATALINA_PID" ]; then
start-stop-daemon --stop --pidfile "$CATALINA_PID" \
--user "$TOMCAT8_USER" \
--retry=TERM/20/KILL/5 >/dev/null
if [ $? -eq 1 ]; then
log_progress_msg "$DESC is not running but pid file exists, cleaning up"
elif [ $? -eq 3 ]; then
PID="`cat $CATALINA_PID`"
log_failure_msg "Failed to stop $NAME (pid $PID)"
exit 1
fi
rm -f "$CATALINA_PID"
rm -rf "$JVM_TMP"
else
log_progress_msg "(not running)"
fi
log_end_msg 0
set -e
;;
status)
set +e
start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null 2>&1
if [ "$?" = "0" ]; then
if [ -f "$CATALINA_PID" ]; then
log_success_msg "$DESC is not running, but pid file exists."
exit 1
else
log_success_msg "$DESC is not running."
exit 3
fi
else
log_success_msg "$DESC is running with pid `cat $CATALINA_PID`"
fi
set -e
;;
restart|force-reload)
if [ -f "$CATALINA_PID" ]; then
$0 stop
sleep 1
fi
$0 start
;;
try-restart)
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
--user $TOMCAT8_USER --exec "$JAVA_HOME/bin/java" \
>/dev/null; then
$0 start
fi
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 1
;;
esac
exit 0
root@puppet:/etc/puppet/modules/tomcat8/templates# cat ubuntu-default-tomcat8.erb
# File Managed by Puppet
# Run Tomcat as this user ID. Not setting this or leaving it blank will use the
# default of tomcat7.
TOMCAT8_USER=<%= @instance_owner %>
# Run Tomcat as this group ID. Not setting this or leaving it blank will use
# the default of tomcat7.
TOMCAT8_GROUP=<%= @instance_group %>
# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
<% if @java_home != '' -%>
JAVA_HOME=<%= @java_home %>
<% end -%>
# You may pass JVM startup parameters to Java here. If unset, the default
# options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
#
# Use "-XX:+UseConcMarkSweepGC" to enable the CMS garbage collector (improved
# response time). If you use that option and you run Tomcat on a machine with
# exactly one CPU chip that contains one or two cores, you should also add
# the "-XX:+CMSIncrementalMode" option.
<% if @java_opts != '' -%>
JAVA_OPTS="<%= @java_opts %>"
<% end -%>
#<% if @catalina_opts != '' -%>
#CATALINA_OPTS="<%= @catalina_opts %>"
#<% end -%>
# Java compiler to use for translating JavaServer Pages (JSPs). You can use all
# compilers that are accepted by Ant's build.compiler property.
#JSP_COMPILER=javac
# Use the Java security manager? (yes/no, default: no)
#TOMCAT8_SECURITY=no
# Number of days to keep logfiles in /var/log/tomcat7. Default is 14 days.
#LOGFILE_DAYS=14
# Location of the JVM temporary directory
# WARNING: This directory will be destroyed and recreated at every startup !
#JVM_TMP=/tmp/tomcat7-temp
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no
root@ts:~# puppet agent --test
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ts
Info: Applying configuration version '1428831538'
Notice: /Stage[main]/Tomcat8::Ubuntu_config/File[/etc/init.d/tomcat8]/ensure: created
Notice: /Stage[main]/Tomcat8::Ubuntu_config/File[/etc/default/tomcat8]/ensure: created
Notice: /Stage[main]/Tomcat8/Exec[uncompress-tomcat]/returns: executed successfully
Notice: /Stage[main]/Tomcat8/Exec[policy-dir]/returns: executed successfully
Notice: /Stage[main]/Tomcat8/Service[tomcat8]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Tomcat8/Service[tomcat8]: Unscheduling refresh on Service[tomcat8]
Notice: Finished catalog run in 5.56 seconds
root@ts:~# ps -ef | grep tomcat8
root 16153 5255 0 18:36 pts/0 00:00:00 tail -f /usr/local/tomcat8/logs/catalina.out
tomcat8 17042 1 23 18:40 ? 00:00:02 /usr/lib/jvm/java-7-oracle/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx128M -XX:+UseConcMarkSweepGC -Djava.endorsed.dirs=/usr/local/tomcat8/endorsed -classpath /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8 -Dcatalina.home=/usr/local/tomcat8 -Djava.io.tmpdir=/tmp/tomcat8-tomcat8-tmp org.apache.catalina.startup.Bootstrap start
Thursday, April 9, 2015
This short configuration continues from below link.
http://wnapdlf.blogspot.jp/2015/04/puppet-new-node-addition.html
# Latest nginx install ubuntu 14.04 trusty and centos7.0
# I created init.pp,config.pp,ubuntu_config for installing and updating latest nginx stable version from nginx.org
# I use cat command to show *.pp and files
root@puppet:/etc/puppet/modules/nginx/manifests# cat init.pp
class nginx {
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
include nginx::config
# do something RHEL specific
# execute 'yum update'
exec { 'yum-update':
command => '/bin/yum -y update'
}
exec { 'yum-nginx-pcre':
command => '/bin/yum -y install pcre-devel',
require => Exec['yum-update']
}
#install nginx ensure
package { 'nginx':
ensure => installed,
}
#running service
service { 'nginx':
ensure => running,
}
}
'ubuntu': {
#inlcude ubuntu_config is for running latest nginx version from nginx.org apt-repo
#When we do not want to install latest nginx package,just comment include line
include nginx::ubuntu_config
# execute 'apt-get update'
exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
}
package { 'nginx':
ensure => latest,
}
# running nginx
service { 'nginx':
ensure => running,
}
}
default: {
# ...
}
}
}
root@puppet:/etc/puppet/modules/nginx/manifests# cat config.pp
# Latest nginx for centos(maybe useful for redhat)
class nginx::config {
file { "/etc/yum.repos.d/nginx.repo":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx.repo",
}
}
root@puppet:/etc/puppet/modules/nginx/manifests# cat ubuntu_config.pp
class nginx::ubuntu_config {
file { "/etc/apt/sources.list.d/nginx.list":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx.ulist",
}
file { "/tmp/nginx_signing.key":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx_signing.key",
}
exec {'key-add':
command => '/usr/bin/apt-key add /tmp/nginx_signing.key'
}
#removing ubuntu repo's nginx packages
exec {'remove-pre-nginx':
command => '/usr/bin/apt-get -y remove --purge nginx nginx-common nginx-core'
}
#$nginx_pkgs = ["nginx","nginx-common","nginx-core"]
#package { $nginx_pkgs: ensure => "absent" }
}
root@puppet:/etc/puppet/modules/nginx/manifests# cd ../files/
root@puppet:/etc/puppet/modules/nginx/files# cat nginx
nginx.repo nginx_signing.key nginx.ulist
#nginx.repo for centos7, nginx_signing.key for add-key for ubuntu, nginx.ulist is apt-repo for ubuntu trusty 14.04
root@puppet:/etc/puppet/modules/nginx/files# cat nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
root@puppet:/etc/puppet/modules/nginx/files# cat nginx.ulist
deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx
# We can get nginx_signing.key from nginx.org.http://nginx.org/keys/nginx_signing.key
root@puppet:/etc/puppet/modules/nginx/files# cat nginx_signing.key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.11 (FreeBSD)
mQENBE5OMmIBCAD+FPYKGriGGf7NqwKfWC83cBV01gabgVWQmZbMcFzeW+hMsgxH
W6iimD0RsfZ9oEbfJCPG0CRSZ7ppq5pKamYs2+EJ8Q2ysOFHHwpGrA2C8zyNAs4I
QxnZZIbETgcSwFtDun0XiqPwPZgyuXVm9PAbLZRbfBzm8wR/3SWygqZBBLdQk5TE
fDR+Eny/M1RVR4xClECONF9UBB2ejFdI1LD45APbP2hsN/piFByU1t7yK2gpFyRt
97WzGHn9MV5/TL7AmRPM4pcr3JacmtCnxXeCZ8nLqedoSuHFuhwyDnlAbu8I16O5
XRrfzhrHRJFM1JnIiGmzZi6zBvH0ItfyX6ttABEBAAG0KW5naW54IHNpZ25pbmcg
a2V5IDxzaWduaW5nLWtleUBuZ2lueC5jb20+iQE+BBMBAgAoBQJOTjJiAhsDBQkJ
ZgGABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRCr9b2Ce9m/YpvjB/98uV4t
94d0oEh5XlqEZzVMrcTgPQ3BZt05N5xVuYaglv7OQtdlErMXmRWaFZEqDaMHdniC
sF63jWMd29vC4xpzIfmsLK3ce9oYo4t9o4WWqBUdf0Ff1LMz1dfLG2HDtKPfYg3C
8NESud09zuP5NohaE8Qzj/4p6rWDiRpuZ++4fnL3Dt3N6jXILwr/TM/Ma7jvaXGP
DO3kzm4dNKp5b5bn2nT2QWLPnEKxvOg5Zoej8l9+KFsUnXoWoYCkMQ2QTpZQFNwF
xwJGoAz8K3PwVPUrIL6b1lsiNovDgcgP0eDgzvwLynWKBPkRRjtgmWLoeaS9FAZV
ccXJMmANXJFuCf26iQEcBBABAgAGBQJOTkelAAoJEKZP1bF62zmo79oH/1XDb29S
YtWp+MTJTPFEwlWRiyRuDXy3wBd/BpwBRIWfWzMs1gnCjNjk0EVBVGa2grvy9Jtx
JKMd6l/PWXVucSt+U/+GO8rBkw14SdhqxaS2l14v6gyMeUrSbY3XfToGfwHC4sa/
Thn8X4jFaQ2XN5dAIzJGU1s5JA0tjEzUwCnmrKmyMlXZaoQVrmORGjCuH0I0aAFk
RS0UtnB9HPpxhGVbs24xXZQnZDNbUQeulFxS4uP3OLDBAeCHl+v4t/uotIad8v6J
SO93vc1evIje6lguE81HHmJn9noxPItvOvSMb2yPsE8mH4cJHRTFNSEhPW6ghmlf
Wa9ZwiVX5igxcvaIRgQQEQIABgUCTk5b0gAKCRDs8OkLLBcgg1G+AKCnacLb/+W6
cflirUIExgZdUJqoogCeNPVwXiHEIVqithAM1pdY/gcaQZmIRgQQEQIABgUCTk5f
YQAKCRCpN2E5pSTFPnNWAJ9gUozyiS+9jf2rJvqmJSeWuCgVRwCcCUFhXRCpQO2Y
Va3l3WuB+rgKjsQ=
=A015
-----END PGP PUBLIC KEY BLOCK-----
#puppet master site.pp contents
root@puppet:/etc/puppet/modules/nginx/files# cat /etc/puppet/manifests/site.pp
node default { }
node 'ts' {
include nginx
include ssh
}
node 'ts1' {
include nginx
include ssh
include java
}
node 'ct7' {
include nginx
}
#centos7 test
[root@ct7 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: nmcli (1.0.0) and NetworkManager (0.9.9.1) versions don't match. Force execution using --nocheck, but the results are unpredictable.
Info: Caching catalog for ct7
Info: Applying configuration version '1428636203'
Notice: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]/content:
--- /etc/yum.repos.d/nginx.repo 2015-04-10 03:21:37.022246045 +0000
+++ /tmp/puppet-file20150410-26365-megu4d 2015-04-10 03:23:23.989743092 +0000
@@ -1,5 +1,5 @@
[nginx]
name=nginx repo
-baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
+baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
Info: Computing checksum on file /etc/yum.repos.d/nginx.repo
Info: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]: Filebucketed /etc/yum.repos.d/nginx.repo to puppet with sum 5acdea38793982f7a967a49fb4ad8580
Notice: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]/content: content changed '{md5}5acdea38793982f7a967a49fb4ad8580' to '{md5}c8473d7b3b6920ac8d59ac3ae6e843e0'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Notice: /Stage[main]/Nginx/Exec[yum-update]/returns: executed successfully
Notice: /Stage[main]/Nginx/Exec[yum-nginx-pcre]/returns: executed successfully
Notice: /Stage[main]/Nginx/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Nginx/Service[nginx]: Unscheduling refresh on Service[nginx]
Notice: Finished catalog run in 43.20 seconds
[root@ct7 ~]# ps -ef | grep nginx
root 26576 1 0 03:24 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 26577 26576 0 03:24 ? 00:00:00 nginx: worker process
root 26581 3127 0 03:24 pts/0 00:00:00 grep --color=auto nginx
#ubuntu nginx install latest version from nginx.org
#ts1 is ubuntu14.04 trusty server
root@ts1:~# puppet agent --test
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ts1
Info: Applying configuration version '1428640592'
Notice: /Stage[main]/Nginx::Ubuntu_config/Exec[remove-pre-nginx]/returns: executed successfully
Notice: /Stage[main]/Nginx::Ubuntu_config/Exec[key-add]/returns: executed successfully
Notice: /Stage[main]/Nginx::Ubuntu_config/File[/etc/apt/sources.list.d/nginx.list]/ensure: defined content as '{md5}e2e568e3450e66cbc1180fc1490d0faa'
Notice: /Stage[main]/Nginx/Exec[apt-update]/returns: executed successfully
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: ensure changed 'purged' to 'latest'
Notice: Finished catalog run in 29.07 seconds
http://wnapdlf.blogspot.jp/2015/04/puppet-new-node-addition.html
# Latest nginx install ubuntu 14.04 trusty and centos7.0
# I created init.pp,config.pp,ubuntu_config for installing and updating latest nginx stable version from nginx.org
# I use cat command to show *.pp and files
root@puppet:/etc/puppet/modules/nginx/manifests# cat init.pp
class nginx {
case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific', 'OracleLinux', 'OEL': {
include nginx::config
# do something RHEL specific
# execute 'yum update'
exec { 'yum-update':
command => '/bin/yum -y update'
}
exec { 'yum-nginx-pcre':
command => '/bin/yum -y install pcre-devel',
require => Exec['yum-update']
}
#install nginx ensure
package { 'nginx':
ensure => installed,
}
#running service
service { 'nginx':
ensure => running,
}
}
'ubuntu': {
#inlcude ubuntu_config is for running latest nginx version from nginx.org apt-repo
#When we do not want to install latest nginx package,just comment include line
include nginx::ubuntu_config
# execute 'apt-get update'
exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
}
package { 'nginx':
ensure => latest,
}
# running nginx
service { 'nginx':
ensure => running,
}
}
default: {
# ...
}
}
}
root@puppet:/etc/puppet/modules/nginx/manifests# cat config.pp
# Latest nginx for centos(maybe useful for redhat)
class nginx::config {
file { "/etc/yum.repos.d/nginx.repo":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx.repo",
}
}
root@puppet:/etc/puppet/modules/nginx/manifests# cat ubuntu_config.pp
class nginx::ubuntu_config {
file { "/etc/apt/sources.list.d/nginx.list":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx.ulist",
}
file { "/tmp/nginx_signing.key":
ensure => present,
owner => 'root',
group => 'root',
mode => 0600,
source => "puppet:///modules/nginx/nginx_signing.key",
}
exec {'key-add':
command => '/usr/bin/apt-key add /tmp/nginx_signing.key'
}
#removing ubuntu repo's nginx packages
exec {'remove-pre-nginx':
command => '/usr/bin/apt-get -y remove --purge nginx nginx-common nginx-core'
}
#$nginx_pkgs = ["nginx","nginx-common","nginx-core"]
#package { $nginx_pkgs: ensure => "absent" }
}
root@puppet:/etc/puppet/modules/nginx/manifests# cd ../files/
root@puppet:/etc/puppet/modules/nginx/files# cat nginx
nginx.repo nginx_signing.key nginx.ulist
#nginx.repo for centos7, nginx_signing.key for add-key for ubuntu, nginx.ulist is apt-repo for ubuntu trusty 14.04
root@puppet:/etc/puppet/modules/nginx/files# cat nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
root@puppet:/etc/puppet/modules/nginx/files# cat nginx.ulist
deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx
# We can get nginx_signing.key from nginx.org.http://nginx.org/keys/nginx_signing.key
root@puppet:/etc/puppet/modules/nginx/files# cat nginx_signing.key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.11 (FreeBSD)
mQENBE5OMmIBCAD+FPYKGriGGf7NqwKfWC83cBV01gabgVWQmZbMcFzeW+hMsgxH
W6iimD0RsfZ9oEbfJCPG0CRSZ7ppq5pKamYs2+EJ8Q2ysOFHHwpGrA2C8zyNAs4I
QxnZZIbETgcSwFtDun0XiqPwPZgyuXVm9PAbLZRbfBzm8wR/3SWygqZBBLdQk5TE
fDR+Eny/M1RVR4xClECONF9UBB2ejFdI1LD45APbP2hsN/piFByU1t7yK2gpFyRt
97WzGHn9MV5/TL7AmRPM4pcr3JacmtCnxXeCZ8nLqedoSuHFuhwyDnlAbu8I16O5
XRrfzhrHRJFM1JnIiGmzZi6zBvH0ItfyX6ttABEBAAG0KW5naW54IHNpZ25pbmcg
a2V5IDxzaWduaW5nLWtleUBuZ2lueC5jb20+iQE+BBMBAgAoBQJOTjJiAhsDBQkJ
ZgGABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRCr9b2Ce9m/YpvjB/98uV4t
94d0oEh5XlqEZzVMrcTgPQ3BZt05N5xVuYaglv7OQtdlErMXmRWaFZEqDaMHdniC
sF63jWMd29vC4xpzIfmsLK3ce9oYo4t9o4WWqBUdf0Ff1LMz1dfLG2HDtKPfYg3C
8NESud09zuP5NohaE8Qzj/4p6rWDiRpuZ++4fnL3Dt3N6jXILwr/TM/Ma7jvaXGP
DO3kzm4dNKp5b5bn2nT2QWLPnEKxvOg5Zoej8l9+KFsUnXoWoYCkMQ2QTpZQFNwF
xwJGoAz8K3PwVPUrIL6b1lsiNovDgcgP0eDgzvwLynWKBPkRRjtgmWLoeaS9FAZV
ccXJMmANXJFuCf26iQEcBBABAgAGBQJOTkelAAoJEKZP1bF62zmo79oH/1XDb29S
YtWp+MTJTPFEwlWRiyRuDXy3wBd/BpwBRIWfWzMs1gnCjNjk0EVBVGa2grvy9Jtx
JKMd6l/PWXVucSt+U/+GO8rBkw14SdhqxaS2l14v6gyMeUrSbY3XfToGfwHC4sa/
Thn8X4jFaQ2XN5dAIzJGU1s5JA0tjEzUwCnmrKmyMlXZaoQVrmORGjCuH0I0aAFk
RS0UtnB9HPpxhGVbs24xXZQnZDNbUQeulFxS4uP3OLDBAeCHl+v4t/uotIad8v6J
SO93vc1evIje6lguE81HHmJn9noxPItvOvSMb2yPsE8mH4cJHRTFNSEhPW6ghmlf
Wa9ZwiVX5igxcvaIRgQQEQIABgUCTk5b0gAKCRDs8OkLLBcgg1G+AKCnacLb/+W6
cflirUIExgZdUJqoogCeNPVwXiHEIVqithAM1pdY/gcaQZmIRgQQEQIABgUCTk5f
YQAKCRCpN2E5pSTFPnNWAJ9gUozyiS+9jf2rJvqmJSeWuCgVRwCcCUFhXRCpQO2Y
Va3l3WuB+rgKjsQ=
=A015
-----END PGP PUBLIC KEY BLOCK-----
#puppet master site.pp contents
root@puppet:/etc/puppet/modules/nginx/files# cat /etc/puppet/manifests/site.pp
node default { }
node 'ts' {
include nginx
include ssh
}
node 'ts1' {
include nginx
include ssh
include java
}
node 'ct7' {
include nginx
}
#centos7 test
[root@ct7 ~]# puppet agent --test
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: nmcli (1.0.0) and NetworkManager (0.9.9.1) versions don't match. Force execution using --nocheck, but the results are unpredictable.
Info: Caching catalog for ct7
Info: Applying configuration version '1428636203'
Notice: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]/content:
--- /etc/yum.repos.d/nginx.repo 2015-04-10 03:21:37.022246045 +0000
+++ /tmp/puppet-file20150410-26365-megu4d 2015-04-10 03:23:23.989743092 +0000
@@ -1,5 +1,5 @@
[nginx]
name=nginx repo
-baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
+baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
Info: Computing checksum on file /etc/yum.repos.d/nginx.repo
Info: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]: Filebucketed /etc/yum.repos.d/nginx.repo to puppet with sum 5acdea38793982f7a967a49fb4ad8580
Notice: /Stage[main]/Nginx::Config/File[/etc/yum.repos.d/nginx.repo]/content: content changed '{md5}5acdea38793982f7a967a49fb4ad8580' to '{md5}c8473d7b3b6920ac8d59ac3ae6e843e0'
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: created
Notice: /Stage[main]/Nginx/Exec[yum-update]/returns: executed successfully
Notice: /Stage[main]/Nginx/Exec[yum-nginx-pcre]/returns: executed successfully
Notice: /Stage[main]/Nginx/Service[nginx]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Nginx/Service[nginx]: Unscheduling refresh on Service[nginx]
Notice: Finished catalog run in 43.20 seconds
[root@ct7 ~]# ps -ef | grep nginx
root 26576 1 0 03:24 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 26577 26576 0 03:24 ? 00:00:00 nginx: worker process
root 26581 3127 0 03:24 pts/0 00:00:00 grep --color=auto nginx
#ubuntu nginx install latest version from nginx.org
#ts1 is ubuntu14.04 trusty server
root@ts1:~# puppet agent --test
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ts1
Info: Applying configuration version '1428640592'
Notice: /Stage[main]/Nginx::Ubuntu_config/Exec[remove-pre-nginx]/returns: executed successfully
Notice: /Stage[main]/Nginx::Ubuntu_config/Exec[key-add]/returns: executed successfully
Notice: /Stage[main]/Nginx::Ubuntu_config/File[/etc/apt/sources.list.d/nginx.list]/ensure: defined content as '{md5}e2e568e3450e66cbc1180fc1490d0faa'
Notice: /Stage[main]/Nginx/Exec[apt-update]/returns: executed successfully
Notice: /Stage[main]/Nginx/Package[nginx]/ensure: ensure changed 'purged' to 'latest'
Notice: Finished catalog run in 29.07 seconds
# Puppet new node addition
# Puppet new node addition
# I suppose we did install centos 7 version via vagrant or other methods and ubuntu14.04 trusy version puppet master.
# Personally I prefer vagrant method for just testing and developing.
Puppet master: ubuntu 14.04 trusty
Puppet new node(client) : centos 7.0
#http://docs.puppetlabs.com/guides/install_puppet/install_el.html
[vagrant@ct7]$ sudo rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
Retrieving http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
warning: /var/tmp/rpm-tmp.DIS9XB: Header V4 RSA/SHA1 Signature, key ID 4bd6ec30: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:puppetlabs-release-7-11 ################################# [100%]
[vagrant@ct7 ~]$ sudo yum install puppet
Installed:
puppet.noarch 0:3.7.5-1.el7
Dependency Installed:
augeas-libs.x86_64 0:1.1.0-17.el7 facter.x86_64 1:2.4.3-1.el7
hiera.noarch 0:1.3.4-1.el7 libselinux-ruby.x86_64 0:2.2.2-6.el7
libyaml.x86_64 0:0.1.4-11.el7_0 pciutils.x86_64 0:3.2.1-4.el7
ruby.x86_64 0:2.0.0.598-24.el7 ruby-augeas.x86_64 0:0.4.1-3.el7
ruby-irb.noarch 0:2.0.0.598-24.el7 ruby-libs.x86_64 0:2.0.0.598-24.el7
ruby-shadow.x86_64 1:2.2.0-2.el7 rubygem-bigdecimal.x86_64 0:1.2.0-24.el7
rubygem-io-console.x86_64 0:0.4.2-24.el7 rubygem-json.x86_64 0:1.7.7-24.el7
rubygem-psych.x86_64 0:2.0.0-24.el7 rubygem-rdoc.noarch 0:4.0.0-24.el7
rubygems.noarch 0:2.0.14-24.el7
Complete!
On puppet master(ubuntu trusty) register new centos7 node hostname ct7
root@puppet:~# cat /etc/hosts | head -6
127.0.0.1 localhost
127.0.1.1 puppet puppet
10.0.0.5 puppet puppet
10.0.0.7 ts
10.0.0.9 ts1
10.0.0.11 ct7
root@puppet:~#
#puppet master domain to /etc/hosts file
[vagrant@ct7 ~]$ sudo vi /etc/hosts
[vagrant@ct7 ~]$ cat /etc/hosts
127.0.0.1 ct7 localhost localhost.localdomain localhost4 localhost4.localdomain4
10.0.0.5 puppet
# centos node new key generating
[vagrant@ct7 ~]$ sudo puppet agent --test
Info: Creating a new SSL key for ct7
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for ct7
Info: Certificate Request fingerprint (SHA256): 3A:B2:29:D5:77:F0:38:3A:D5:F6:06:07:39:21:9E:93:BC:1F:D3:36:96:17:BF:28:2D:41:3A:3A:90:6C:D9:D1
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled
[vagrant@ct7 ~]$
#ct7 register to puppet.conf
root@puppet:~# vi /etc/puppet/puppet.conf
[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
#templatedir=$confdir/templates
prerun_command=/etc/puppet/etckeeper-commit-pre
postrun_command=/etc/puppet/etckeeper-commit-post
dns_alt_names = puppet,ts,ts1,ct7
[master]
# These are needed when the puppetmaster is run by passenger
# and can safely be removed if webrick is used.
ssl_client_header = SSL_CLIENT_S_DN
ssl_client_verify_header = SSL_CLIENT_VERIFY
root@puppet:~# puppet cert --list
"ct7" (SHA256) 3A:B2:29:D5:77:F0:38:3A:D5:F6:06:07:39:21:9E:93:BC:1F:D3:36:96:17:BF:28:2D:41:3A:3A:90:6C:D9:D1
root@puppet:~#
root@puppet:~# puppet cert sign ct7
Notice: Signed certificate request for ct7
Notice: Removing file Puppet::SSL::CertificateRequest ct7 at '/var/lib/puppet/ssl/ca/requests/ct7.pem'
# I suppose we did install centos 7 version via vagrant or other methods and ubuntu14.04 trusy version puppet master.
# Personally I prefer vagrant method for just testing and developing.
Puppet master: ubuntu 14.04 trusty
Puppet new node(client) : centos 7.0
#http://docs.puppetlabs.com/guides/install_puppet/install_el.html
[vagrant@ct7]$ sudo rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
Retrieving http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
warning: /var/tmp/rpm-tmp.DIS9XB: Header V4 RSA/SHA1 Signature, key ID 4bd6ec30: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:puppetlabs-release-7-11 ################################# [100%]
[vagrant@ct7 ~]$ sudo yum install puppet
Installed:
puppet.noarch 0:3.7.5-1.el7
Dependency Installed:
augeas-libs.x86_64 0:1.1.0-17.el7 facter.x86_64 1:2.4.3-1.el7
hiera.noarch 0:1.3.4-1.el7 libselinux-ruby.x86_64 0:2.2.2-6.el7
libyaml.x86_64 0:0.1.4-11.el7_0 pciutils.x86_64 0:3.2.1-4.el7
ruby.x86_64 0:2.0.0.598-24.el7 ruby-augeas.x86_64 0:0.4.1-3.el7
ruby-irb.noarch 0:2.0.0.598-24.el7 ruby-libs.x86_64 0:2.0.0.598-24.el7
ruby-shadow.x86_64 1:2.2.0-2.el7 rubygem-bigdecimal.x86_64 0:1.2.0-24.el7
rubygem-io-console.x86_64 0:0.4.2-24.el7 rubygem-json.x86_64 0:1.7.7-24.el7
rubygem-psych.x86_64 0:2.0.0-24.el7 rubygem-rdoc.noarch 0:4.0.0-24.el7
rubygems.noarch 0:2.0.14-24.el7
Complete!
On puppet master(ubuntu trusty) register new centos7 node hostname ct7
root@puppet:~# cat /etc/hosts | head -6
127.0.0.1 localhost
127.0.1.1 puppet puppet
10.0.0.5 puppet puppet
10.0.0.7 ts
10.0.0.9 ts1
10.0.0.11 ct7
root@puppet:~#
#puppet master domain to /etc/hosts file
[vagrant@ct7 ~]$ sudo vi /etc/hosts
[vagrant@ct7 ~]$ cat /etc/hosts
127.0.0.1 ct7 localhost localhost.localdomain localhost4 localhost4.localdomain4
10.0.0.5 puppet
# centos node new key generating
[vagrant@ct7 ~]$ sudo puppet agent --test
Info: Creating a new SSL key for ct7
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for ct7
Info: Certificate Request fingerprint (SHA256): 3A:B2:29:D5:77:F0:38:3A:D5:F6:06:07:39:21:9E:93:BC:1F:D3:36:96:17:BF:28:2D:41:3A:3A:90:6C:D9:D1
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled
[vagrant@ct7 ~]$
#ct7 register to puppet.conf
root@puppet:~# vi /etc/puppet/puppet.conf
[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
#templatedir=$confdir/templates
prerun_command=/etc/puppet/etckeeper-commit-pre
postrun_command=/etc/puppet/etckeeper-commit-post
dns_alt_names = puppet,ts,ts1,ct7
[master]
# These are needed when the puppetmaster is run by passenger
# and can safely be removed if webrick is used.
ssl_client_header = SSL_CLIENT_S_DN
ssl_client_verify_header = SSL_CLIENT_VERIFY
root@puppet:~# puppet cert --list
"ct7" (SHA256) 3A:B2:29:D5:77:F0:38:3A:D5:F6:06:07:39:21:9E:93:BC:1F:D3:36:96:17:BF:28:2D:41:3A:3A:90:6C:D9:D1
root@puppet:~#
root@puppet:~# puppet cert sign ct7
Notice: Signed certificate request for ct7
Notice: Removing file Puppet::SSL::CertificateRequest ct7 at '/var/lib/puppet/ssl/ca/requests/ct7.pem'
Puppet oracle java7 installation.
Puppet oracle java7 installation.
root@puppet:/etc/puppet/modules# puppet module install puppetlabs-apt
Warning: Setting templatedir is deprecated. See http://links.puppetlabs.com/env-settings-deprecations
(at /usr/lib/ruby/vendor_ruby/puppet/settings.rb:1139:in `issue_deprecation_warning')
Notice: Preparing to install into /etc/puppet/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppet/modules
└─┬ puppetlabs-apt (v1.8.0)
└── puppetlabs-stdlib (v4.5.1)
root@puppet:/etc/puppet/modules#
root@puppet:/etc/puppet/modules/java# cat manifests/init.pp
class java {
include java::default
}
root@puppet:/etc/puppet/modules/java# cat manifests/default.pp
# From https://gist.github.com/hameno/8219185
class java::default {
class { 'apt': }
# Add ppa
apt::ppa { 'ppa:webupd8team/java':} ->
# Prepare response file
file { "/tmp/oracle-java7-installer.preseed":
source => 'puppet:///modules/java/java.response',
mode => 600,
backup => false,
} ->
# Install java
package { "oracle-java7-installer":
ensure => "installed",
responsefile => '/tmp/oracle-java7-installer.preseed'
} ->
package { "oracle-java7-set-default": ensure => "installed" }
}
root@puppet:/etc/puppet/modules/java# cat files/java.response
# From https://gist.github.com/hameno/8219185
oracle-java7-installer shared/accepted-oracle-license-v1-1 select true
oracle-java7-installer shared/accepted-oracle-license-v1-1 seen true
root@puppet:/etc/puppet/modules/java/manifests# cat init.pp
class java {
include java::default
}
root@puppet:/etc/puppet/manifests# cat site.pp
node default { }
node 'ts' {
include nginx
include ssh
}
node 'ts1' {
include nginx
include ssh
include java
}
root@ts1:~# puppet agent --test
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ts1
Info: Applying configuration version '1428587206'
Notice: /Stage[main]/Java::Default/File[/tmp/oracle-java7-installer.preseed]/ensure: defined content as '{md5}0ab981127e3d597b2175f9959eb70c3f'
Notice: /Stage[main]/Nginx/Exec[apt-update]/returns: executed successfully
Info: Package[oracle-java7-installer](provider=apt): Preseeding /tmp/oracle-java7-installer.preseed to debconf-set-selections
Notice: /Stage[main]/Java::Default/Package[oracle-java7-installer]/ensure: ensure changed 'purged' to 'present'
Notice: /Stage[main]/Java::Default/Package[oracle-java7-set-default]/ensure: ensure changed 'purged' to 'present'
Notice: Finished catalog run in 243.44 seconds
root@ts1:~# which java
/usr/bin/java
root@ts1:~# java -version
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)
root@puppet:/etc/puppet/modules# puppet module install puppetlabs-apt
Warning: Setting templatedir is deprecated. See http://links.puppetlabs.com/env-settings-deprecations
(at /usr/lib/ruby/vendor_ruby/puppet/settings.rb:1139:in `issue_deprecation_warning')
Notice: Preparing to install into /etc/puppet/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppet/modules
└─┬ puppetlabs-apt (v1.8.0)
└── puppetlabs-stdlib (v4.5.1)
root@puppet:/etc/puppet/modules#
root@puppet:/etc/puppet/modules/java# cat manifests/init.pp
class java {
include java::default
}
root@puppet:/etc/puppet/modules/java# cat manifests/default.pp
# From https://gist.github.com/hameno/8219185
class java::default {
class { 'apt': }
# Add ppa
apt::ppa { 'ppa:webupd8team/java':} ->
# Prepare response file
file { "/tmp/oracle-java7-installer.preseed":
source => 'puppet:///modules/java/java.response',
mode => 600,
backup => false,
} ->
# Install java
package { "oracle-java7-installer":
ensure => "installed",
responsefile => '/tmp/oracle-java7-installer.preseed'
} ->
package { "oracle-java7-set-default": ensure => "installed" }
}
root@puppet:/etc/puppet/modules/java# cat files/java.response
# From https://gist.github.com/hameno/8219185
oracle-java7-installer shared/accepted-oracle-license-v1-1 select true
oracle-java7-installer shared/accepted-oracle-license-v1-1 seen true
root@puppet:/etc/puppet/modules/java/manifests# cat init.pp
class java {
include java::default
}
root@puppet:/etc/puppet/manifests# cat site.pp
node default { }
node 'ts' {
include nginx
include ssh
}
node 'ts1' {
include nginx
include ssh
include java
}
root@ts1:~# puppet agent --test
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ts1
Info: Applying configuration version '1428587206'
Notice: /Stage[main]/Java::Default/File[/tmp/oracle-java7-installer.preseed]/ensure: defined content as '{md5}0ab981127e3d597b2175f9959eb70c3f'
Notice: /Stage[main]/Nginx/Exec[apt-update]/returns: executed successfully
Info: Package[oracle-java7-installer](provider=apt): Preseeding /tmp/oracle-java7-installer.preseed to debconf-set-selections
Notice: /Stage[main]/Java::Default/Package[oracle-java7-installer]/ensure: ensure changed 'purged' to 'present'
Notice: /Stage[main]/Java::Default/Package[oracle-java7-set-default]/ensure: ensure changed 'purged' to 'present'
Notice: Finished catalog run in 243.44 seconds
root@ts1:~# which java
/usr/bin/java
root@ts1:~# java -version
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)
Subscribe to:
Posts (Atom)