Dns 如何使用Puppet管理resolv.conf

Dns 如何使用Puppet管理resolv.conf,dns,puppet,Dns,Puppet,我有一些主机显式管理resolv.conf文件。我还有其他人依赖NetworkManager,它做很多事情,包括编写resolv.conf文件。是否有一种一致的方式来管理Puppet的这些信息,例如某个模块,在该模块中,我可以从语义上描述DNS服务器和搜索顺序,然后根据主机的配置预期会发生正确的事情?如果失败,是否有一个模块可以连接到NetworkManager以执行我想要的操作?写出一个显式的resolv.conf文件相当简单,所以如果我这样做的话,我不需要任何帮助。您可以使用模板。以下是一个

我有一些主机显式管理resolv.conf文件。我还有其他人依赖NetworkManager,它做很多事情,包括编写resolv.conf文件。是否有一种一致的方式来管理Puppet的这些信息,例如某个模块,在该模块中,我可以从语义上描述DNS服务器和搜索顺序,然后根据主机的配置预期会发生正确的事情?如果失败,是否有一个模块可以连接到NetworkManager以执行我想要的操作?写出一个显式的resolv.conf文件相当简单,所以如果我这样做的话,我不需要任何帮助。

您可以使用模板。以下是一个模板示例:

domain <%= @param1 %>
search <%= @param1 %> <%= @param2 %>
nameserver <%= @dns1 %>
nameserver <%= @dns2 %>
<%= @dns1_ip6 %>
<%= @dns2_ip6 %>

您可以在清单之前创建if语句: *如果未安装NetworkManager,请使用file\u line(我所知道的最好的puppet模块之一)编辑resolv.conf。 *否则请确保NetworkManager正在运行

如果您希望某些服务器上也有NetowrkManager,那么可以创建一个自定义factor?类似于default_resolv_conf,然后您可以显式: 如果$custom\u resolv\u conf{ 文件_行{'..': ..... }


希望这有帮助,这看起来有一段时间是开放的,但我必须自己处理。我发现最好的方法是让puppet管理文件/etc/resolvconf/resolv.conf.d/head和/etc/resolvconf/resolv.conf.d/tail,这取决于您需要添加的resolv.conf选项。然后,您可以让puppet exec将更新推送到/etc/resolv.conf:

    # Create a custom file to append to resolv.conf
file {'/etc/resolvconf/resolv.conf.d/tail':
  ensure    => present,
  mode      => '0644',
  content   => '# Custom resolv.conf options added by Puppet profiles::resolv',
} ->
# Override the default for retry attempts
file_line {"options attempts:${$attempts}":
  ensure  => present,
  path    => '/etc/resolvconf/resolv.conf.d/tail',
  line    => "options attempts:${$attempts}",
  match   => '^options attempts:.*',
} ->
# Force an update to resolv.conf
exec {'update-resolvconf':
  command => 'resolvconf -u',
  user    => 'root',
  path    => ['/sbin/'],
}

谢谢。我已经有了类似的方法来显式管理resolv.conf,但它并没有真正解决在NetworkManager生成resolv.conf的主机上该做什么。
    # Create a custom file to append to resolv.conf
file {'/etc/resolvconf/resolv.conf.d/tail':
  ensure    => present,
  mode      => '0644',
  content   => '# Custom resolv.conf options added by Puppet profiles::resolv',
} ->
# Override the default for retry attempts
file_line {"options attempts:${$attempts}":
  ensure  => present,
  path    => '/etc/resolvconf/resolv.conf.d/tail',
  line    => "options attempts:${$attempts}",
  match   => '^options attempts:.*',
} ->
# Force an update to resolv.conf
exec {'update-resolvconf':
  command => 'resolvconf -u',
  user    => 'root',
  path    => ['/sbin/'],
}