puppet 语法学习

  1. 条件语句
    • case 语句
case $operatingsystem {
redhat: { service { "httpd":   ensure => running }}
debian:  { service { "apache":  ensure => running }}
default: { service { "apache2": ensure => running }}
} 
  •  if 条件语句
 if $is_virtual {
warning('target is virtual.')
}
elsif $operatingsystem == 'CentOS' {
warning('module doesnt work on this OS.')
}
else {
include roles::base
}
  • 选择语句
$rootgroup = $osfamily ? {
 'Solaris' => 'wheel',
 /(Darwin|FreeBSD)/ => 'wheel',
 default => 'root',
}
  • 除非语句
 unless $memorysize > 2048 {
$maxclient = 1000
}
  • in语句
if $monitortool in [ 'zabbix','nagios','cacti' ]