分类: 系统运维
2015-02-12 14:54:02
class build_instances ($instance_list={}) {
define run {
$temp = split($name, '\|')
$server = $temp[0]
$instance = $temp[1]
$type = inline_template("<%= @instance[0, @instance.length - 2]%>")
$instance_id = inline_template("<%= @instance[@instance.length - 2, 2] %>")
$shutdown_port = 8100 + $instance_id
$http_port = 8300 + $instance_id
$ajp_port = 9100 + $instance_id
$proxy_port = 9500 + $instance_id
$jmx_port = 8500 + $instance_id
$soffice_cron_min = 0 + $instance_id
$max_threads = 100
$accept_count = 5
$appdynamics = member(hiera('appdynamics_enabled', []), $instance)
if $type == 'aspose' {
$xmx_size = 32G
$xms_size = 32G
$new_size = 24G
$max_new_size = 24G
$aspose = "true"
if ! defined(Package['aspose-fonts']) {
package { 'aspose-fonts':
ensure => installed,
require => Yumrepo["zuoraextrasrepo"],
}
}
} elsif $type == 'bet_pdf' {
$xmx_size = 8G
$xms_size = 8G
$new_size = 3200M
$max_new_size = 3200M
$aspose = undef
} else {
$xmx_size = 8G
$xms_size = 8G
$perm_size = 1G
$max_perm_size = 1G
$aspose = undef
}
if $server =~ /.*prod.*/ or $server =~ /.*sbx.*/ {
$jstack_cron_if_prod = "true"
}
else {
$jstack_cron_if_prod = undef
}
if $soffice_cron_min >= 60 {
$soffice_cron_min_n = $soffice_cron_min - 60
} else {
$soffice_cron_min_n = $soffice_cron_min
}
if $fqdn == "$server" {
notice ("Buidling instance on $instance")
include tomcat
tomcat::instance { $instance:
instance_id => $instance_id,
shutdown_port => $shutdown_port,
http_port => $http_port,
ajp_port => $ajp_port,
proxy_port => $proxy_port,
jmx_port => $jmx_port,
max_threads => $max_threads,
accept_count => $accept_count,
xmx_size => $xmx_size,
xms_size => $xms_size,
perm_size => $perm_size,
max_perm_size => $max_perm_size,
new_size => $new_size,
max_new_size => $max_new_size,
soffice_cron_min => $soffice_cron_min_n,
jstack_cron_if_prod => $jstack_cron_if_prod,
aspose => $aspose,
appdynamics => $appdynamics,
}
include groundworkjdma
groundworkjdma::instance { $instance:
server => $server,
instance_id => $instance_id,
type => $type,
}
include jolokia
jolokia::multi_jolokia { "jolokia_${server}_${instance_id}_${type}":
jolokia_version => "1.2.3",
jolokia_path => "/home/zapp/apps/${instance_id}",
server => $server,
instance_id => $instance_id,
type => $type,
}
}
}
define hashDebug($server, $list) {
$instance = split($list, ' ')
$new_instance = inline_template("<%=
newlist= @list.split(' ')
updated_list = String.new
for item in newlist
new_value = @server + \"|\" + item
updated_list = updated_list + new_value + \",\"
end
updated_list.chomp(',')
%>")
$new = split($new_instance, ',')
run { $new: }
}
###
create_resources(hashDebug, $instance_list)
}
node /\d+\.(fet|bet|).prod.*/ {
$instance_list = {
instance_set1 => { server => '5.bet.prod.slv.zuora', list => 'bet00 bet01 bet03 bet08 bet20 bet23 bet24 bet25 bet26 bet29 bet30 bet33 bet34 bet69' },
instance_set2 => { server => '6.bet.prod.slv.zuora', list => 'bet00 bet01 bet03 bet08 bet20 bet23 bet25 bet29 bet30 bet33 bet34 bet64 bet65 bet66' },
instance_set14 => { server => '4.fet.prod.slv.zuora', list => 'fet03 fet04 fet05' },
instance_set15 => { server => '13.bet.prod.slv.zuora', list => '' },
instance_set16 => { server => '14.bet.prod.slv.zuora', list => '' }
}
class { 'build_instances':
instance_list => $instance_list,
}
}
#这里用到了member/inline_template函数,
Here's an example of using inline_template:
Pass your Ruby code to inline_template within the Puppet manifest, as follows:
cron { 'chkrootkit': command => '/usr/sbin/chkrootkit > /var/log/chkrootkit.log 2>&1',
# inline_template("<%= Time.now.gmtime.wday %>") hour => inline_template('<%= @hostname.sum % 24 %>'), minute => '00', }
Anything inside the string passed to inline_template is executed as if it were an ERB template. That is, anything inside <%= and %> delimiters will be executed as Ruby .