I am very new to Puppet programming.
I have the following class which configures the resolv.conf file correctly:
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,
}
}
I created a custom fact default_gateway
which should find the client default gateway, and according to that I want to then assign different name servers.
I tried to enter the condition at the beginning of the dnsclient class:
class dnsclient
if $default_gateway == 'DG ip' {
$nameservers = [ 'ns1 ip',
'ns2 ip' ,
'ns3 ip' ],
}
But I am getting a syntax error on the client, please advise. Where do I place the if statement to assign different name servers if the default gateway is different.
I assume you need to also remove the $nameservers
class parameter, so you would change the beginning of the file to:
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'],
}
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.