# Parameterized Classes on puppet master
[root@linux64-puppet-server ~]# puppet module list/etc/puppet/modules
+- pptdeploy(???)
[root@linux64-puppet-server ~]# puppet config print confdir
/etc/puppet
[root@linux64-puppet-server ~]# find /etc/puppet/manifests/
/etc/puppet/manifests/
/etc/puppet/manifests/site.pp
[root@linux64-puppet-server ~]# find /etc/puppet/modules/
/etc/puppet/modules/
/etc/puppet/modules/pptdeploy
/etc/puppet/modules/pptdeploy/manifests
/etc/puppet/modules/pptdeploy/manifests/init.pp
/etc/puppet/modules/pptdeploy/manifests/install.pp
/etc/puppet/modules/pptdeploy/manifests/lockforinstall.pp
/etc/puppet/modules/pptdeploy/manifests/uninstall.pp
/etc/puppet/modules/pptdeploy/manifests/unlockforinstall.pp
# Define Puppet Parameterized Classes
cat /etc/puppet/modules/pptdeploy/manifests/init.pp
class pptdeploy {}
cat /etc/puppet/modules/pptdeploy/manifests/install.pp
class pptdeploy::install($pptdeploy_release, $pptdeploy_install_dir, $pptdeploy_product_shortname, $pptdeploy_product_name, $pptdeploy_response_file) {notify{ ">>> Starting to install ${pptdeploy_release} ${pptdeploy_product_name} ...":
before => File [ installer ] }
file { "installer":
path => "${pptdeploy_install_dir}/${pptdeploy_product_shortname}/${pptdeploy_product_name}.bin",
mode => '0755', }
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
exec { "install ${pptdeploy_release} ${pptdeploy_product_name} ...":
command => "${pptdeploy_install_dir}/${pptdeploy_product_shortname}/${pptdeploy_product_name}.bin -i silent -DMY_RESPONSE_FILE=${pptdeploy_install_dir}/${pptdeploy_product_shortname}/${pptdeploy_response_file}",
timeout => 0,
creates => "/etc/install_registry/${pptdeploy_release}_${pptdeploy_product_shortname}_installed",
require => File [ installer ] }
exec { "<<< verify ${pptdeploy_release} ${pptdeploy_product_name} installation ...":
command => "cat /etc/install_registry/${pptdeploy_product_name}.properties",
logoutput => true,
creates => "/etc/install_registry/${pptdeploy_release}_${pptdeploy_product_shortname}_installed",
require => Exec [ "install pptdeploy ${pptdeploy_release} ${pptdeploy_product_name} ..." ] }
exec { "Lock installation for ${pptdeploy_product_name} ...":
command => "/bin/touch /etc/install_registry/${pptdeploy_release}_${pptdeploy_product_shortname}_installed",
creates => "/etc/install_registry/${pptdeploy_release}_${pptdeploy_product_shortname}_installed",
require => Exec [ "<<< verify ${pptdeploy_release} ${pptdeploy_product_name} installation ..." ] }
}
cat /etc/puppet/modules/pptdeploy/manifests/lockforinstall.pp
class pptdeploy::lockforinstall($pptdeploy_release, $pptdeploy_install_dir, $pptdeploy_product_shortname, $pptdeploy_product_name, $pptdeploy_response_file) {Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
exec { "Lock installation for ${pptdeploy_product_name} ...":
command => "/bin/touch /etc/install_registry/${pptdeploy_release}_${pptdeploy_product_shortname}_installed",}
}
cat /etc/puppet/modules/pptdeploy/manifests/uninstall.pp
class pptdeploy::uninstall($pptdeploy_release, $pptdeploy_install_dir, $pptdeploy_product_shortname, $pptdeploy_product_name, $pptdeploy_response_file) {notify{ ">>> Starting to uninstall ${pptdeploy_product_name} ...": }
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
exec { "uninstall ${pptdeploy_product_name} ...":
command => "/opt/Uninstall_${pptdeploy_product_name} -i silent -uninstall",
timeout => 0,
require => Exec [ "Unlock installation for ${pptdeploy_product_name} ..." ] }
exec { "Unlock installation for ${pptdeploy_product_name} ...":
command => "rm -f /etc/install_registry/*_${pptdeploy_product_shortname}_installed",
timeout => 0, }
}
cat /etc/puppet/modules/pptdeploy/manifests/unlockforinstall.pp
class pptdeploy::unlockforinstall($pptdeploy_release, $pptdeploy_install_dir, $pptdeploy_product_shortname, $pptdeploy_product_name, $pptdeploy_response_file) {Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
exec { "Unlock installation for ${pptdeploy_product_name} ...":
command => "rm -f /etc/install_registry/*_${pptdeploy_product_shortname}_installed",}
}
# Global namespace - declare a Parameterized Class
cat /etc/puppet/manifests/site.ppnode default {
}
################################################
$pptdeploy_release = "3.0"
$pptdeploy_install_dir = "/mnt/work/COTS_install_sources"
$pptdeploy_product_shortname = "COTS"
$pptdeploy_product_name = "COTS-3.0"
$pptdeploy_response_file = "cots.response"
#-----------------------
# pptdeploy installation
#-----------------------
node /linux64-puppet.*\.domain\.com/ {
class { 'pptdeploy::install':
pptdeploy_release => $pptdeploy_release,
pptdeploy_install_dir => $pptdeploy_install_dir,
pptdeploy_product_shortname => $pptdeploy_product_shortname,
pptdeploy_product_name => $pptdeploy_product_name,
pptdeploy_response_file => $pptdeploy_response_file,
}
}
#-----------------------
# pptdeploy uninstallation
#-----------------------
# node /linux64-puppet.*\.domain\.com/ {
# class { 'pptdeploy::uninstall':
# pptdeploy_release => '3.0',
# pptdeploy_install_dir => '/mnt/work/COTS_install_sources',
# pptdeploy_product_shortname => 'COTS',
# pptdeploy_product_name => 'COTS-3.0',
# pptdeploy_response_file => 'cots.response,
# }
# }
################################################
# deploy on puppet agent
[root@linux64-puppet-agent ~]# puppet agent -t --noopinfo: Caching catalog for linux64-puppet-agent
info: Applying configuration version '1340827332'
notice: >>> Starting to install 3.0 COTS-3.0 ...
notice: /Stage[main]/pptdeploy::install/Notify[>>> Starting to install 3.0 COTS-3.0 ...]/message: defined 'message' as '>>> Starting to install 3.0 COTS-3.0 ...'
notice: Finished catalog run in 0.08 seconds
No comments:
Post a Comment