如何添加几行文件与Puppet

我没有find任何优雅的方式来添加几行到现有的文件。

我注意到了简单文本模式的 wiki页面,但我必须在/etc/network/interfaces添加一个块。

任何线索?

我同意augeas是迄今为止你所尝试的最好的答案。

我也会推荐stdlib木偶库中的file_line资源。 它往往比augeas更轻。

您必须为每一行定义一个资源,如果顺序很重要,则可以在调用之间添加依赖关系。

示例用法:

  file_line { "no_ipv6_networking": path => "/etc/sysconfig/network", line => "NETWORKING_IPV6=no", match => "^NETWORKING_IPV6=", } 

你为此使用了augeastypes,但理想的解决scheme是使用netcf因为你想pipe理networking接口。

前段时间,我开始了一个Puppet Netcf提供者 。 它还没有准备好生产 ,但是如果你有一些Ruby技能,这可能是你需要的最好的解决scheme(而且PR也是非常受欢迎的)。

Netcf提供程序将XML接口定义作为input,例如:

 netcf_if {"eth1": ensure => up, definition => ' <interface type="ethernet" name="eth1"> <start mode="onboot"/> <protocol family="ipv4"> <ip address="192.168.0.5" prefix="24"/> <route gateway="192.168.0.1"/> </protocol> </interface> '; } 

您可以在Netcf存储库中find更多XML定义的例子 。