![](/img/trans.png)
[英]How to add multiple source in one class in puppet manifest and how to declare that?
[英]add if statment into puppet class manifest
我是Puppet編程的新手。
我有以下用於正確配置resolv.conf文件的類:
class dnsclient (
$nameservers = [ 'ns1 ip',
'ns2 ip' ,
'ns3 ip' ],
$options = [ 'rotate',
'timeout:5',
'attempts:3' ],
$search = [ 'example.com',
'example2.com' ],
$domain = 'UNSET',
$sortlist = ['UNSET'],
$resolver_config_file = '/etc/resolv.conf',
$resolver_config_file_ensure = 'file',
$resolver_config_file_owner = 'root',
$resolver_config_file_group = 'root',
$resolver_config_file_mode = '0644',
) {
# Validates domain
if is_domain_name($domain) != true {
fail("Domain name, ${domain}, is invalid.")
}
# Validates $resolver_config_file_ensure
case $resolver_config_file_ensure {
'file', 'present', 'absent': {
# noop, these values are valid
}
default: {
fail("Valid values for \$resolver_config_file_ensure are \'absent\', \'file\', or \'present\'. Specified value is ${resolver_config_file_ensure}")
}
}
file { 'dnsclient_resolver_config_file':
ensure => $resolver_config_file_ensure,
content => template('dnsclient/resolv.conf.erb'),
path => $resolver_config_file,
owner => $resolver_config_file_owner,
group => $resolver_config_file_group,
mode => $resolver_config_file_mode,
}
}
我創建了一個自定義事實default_gateway
,它應該找到客戶端的默認網關,並據此我想分配不同的名稱服務器。
我試圖在dnsclient類的開頭輸入條件:
class dnsclient
if $default_gateway == 'DG ip' {
$nameservers = [ 'ns1 ip',
'ns2 ip' ,
'ns3 ip' ],
}
但是我在客戶端遇到語法錯誤,請告知。 如果默認網關不同,則在何處放置if語句以分配不同的名稱服務器。
我假設您還需要刪除$nameservers
類參數,因此您可以將文件的開頭更改為:
class dnsclient (
# This parameter is no longer required?
# $nameservers = [ 'ns1 ip',
# 'ns2 ip' ,
# 'ns3 ip' ],
$options = [ 'rotate',
'timeout:5',
'attempts:3' ],
$search = [ 'example.com',
'example2.com' ],
$domain = 'UNSET',
$sortlist = ['UNSET'],
$resolver_config_file = '/etc/resolv.conf',
$resolver_config_file_ensure = 'file',
$resolver_config_file_owner = 'root',
$resolver_config_file_group = 'root',
$resolver_config_file_mode = '0644',
) {
# Your code goes here:
if $default_gateway == 'DG ip' {
$nameservers = ['ns1 ip', 'ns2 ip', 'ns3 ip'],
}
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.