puppet 配置 5 常见例子

2/13/2017来源:经验技巧人气:3126

变量复用

说明:

变量定义后可以直接调用变量名称使用

范例:

$etcd_controller1='10.100.84.22' $etcd_controller2='10.100.84.23' $etcd_controller3='10.100.84.24' $etcd_host1='gx-yun-084022.vclound.com' $etcd_host2='gx-yun-084023.vclound.com' $etcd_host3='gx-yun-084024.vclound.com' $etcd_connect="$etcd_host1=http://$etcd_host1:2380,$etcd_host2=http://$etcd_host2:2380,$etcd_host3=http://$etcd_host3:2380" $etcdcluster="$etcd_controller1:2379,$etcd_controller2:2379,$etcd_controller3:2379"

变量的判断

说明:

可以利用 case , if 的方式进行判断, 效果一样 针对不同的主机, 定义不同的变量使用

范例

$myipaddress=$ipaddress_vlanbr0 if $myipaddress =~ /^10\.201\.\\*/ { $ntpserver = '10.201.100.21' } elsif $myipaddress =~ /^10\.200\.\\*/ { $ntpserver = '10.200.100.21' } elsif $myipaddress =~ /^10\.205\.\\*/ { $ntpserver = '10.205.100.25' } elsif $myipaddress =~ /^192\.168\.\\*/ { $ntpserver = [ '10.199.129.21', '10.199.129.22' ] } elsif $myipaddress =~ /^10\.100\.\\*/ { $ntpserver = [ '10.199.129.21', '10.199.129.22' ] }

case 语法