如何使用Puppet管理resolv.conf

时间:2014-11-06 15:38:39

标签: dns puppet

我有一些显式管理resolv.conf文件的主机。我有其他人依赖NetworkManager,它做了很多事情,包括编写resolv.conf文件。是否有一致的方法来管理Pupppet的这些信息,例如我可以在语义上描述DNS服务器和搜索顺序的某个模块,然后根据主机的配置方式预计会发生正确的事情?如果失败了,是否有一个模块可以与NetworkManager连接以实现我想要的功能?写出一个明确的resolv.conf文件是相当简单的,所以如果我走那条路,我就不需要帮助了。

3 个答案:

答案 0 :(得分:1)

您可以在清单之前创建if语句: *如果未安装NetworkManager,请使用 file_line (我认识的最好的木偶模块之一http://puppetlabs.com/blog/module-of-the-week-puppetlabsstdlib-puppet-labs-standard-library)来编辑resolv.conf。 *确保NetworkManager正在运行。

如果你想让一些人在拥有NetowrkManager的服务器上安装客户resolv.conf,也许可以创建一个自定义的设备?像default_resolv_conf之类的东西,然后你显示: if $ custom_resolv_conf {     file_line {' ..':     .....     }

希望这有帮助

答案 1 :(得分:0)

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

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

您可以在条件语句中为这些参数添加不同的值,具体取决于节点组...例如:

 if ( $domain ){
    $param1 = $domain
    $param2 = $someOtherDomain
    $dns1 = 1.1.1.1
    $dns2 = 1.1.1.2
 }

答案 2 :(得分:0)

这看起来有一段时间了,但我自己必须解决。我发现最好的方法是让木偶根据需要添加的resolv.conf选项来管理文件/etc/resolvconf/resolv.conf.d/head和/etc/resolvconf/resolv.conf.d/tail。然后,您可以让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/'],
}