【问题标题】:best way to write a puppet manifest for adding Linux auto.misc entries without overwriting the existing config lines编写木偶清单以添加 Linux auto.misc 条目而不覆盖现有配置行的最佳方法
【发布时间】:2015-08-11 00:37:50
【问题描述】:

我目前正在编写一个用于向 auto.misc 文件添加行的 puppet 模块。

我使用 augeas 向 auto.misc 文件添加了一个新条目,我想出了下面的内容,每次运行时它都运行良好而无需重复。

augeas { "new auto mountpoint":

        context => "/files/etc/auto.misc",
        changes => [

            "set 01 'store'",
            "set 01/opt[1] 'ro'",
            "set 01/opt[2] 'soft'",
            "set 01/opt[3] 'intr'",
            "set 01/location/1/host 'uxkickstart.thenational.com'",
            "set 01/location/1/path '/common'",
        ],

        onlyif  => "match *[. = 'store'] size == 0",
    }

现在,如果我想为特定的挂载点添加新选项,它永远不会更新。

如果有人能告诉我最好的方法是什么,或者以不同的方式使用 augeas 来解决这里的问题,那就太好了。

谢谢

【问题讨论】:

    标签: puppet augeas automount


    【解决方案1】:

    如果您一次只需要添加/修改一行,那么来自puppetlabs-stdlibfile_line 资源比 augeas 更易于使用。

    【讨论】:

    • 我确实尝试过,但缺点是,即使它要替换的该行中的单个单词丢失,它也会添加重复条目。
    • 你应该可以使用 match 参数来做到这一点。
    【解决方案2】:

    这里最好的选择是编写一个适当的类型+augeas 提供程序,而不是使用augeas 类型。这将允许您将选项指定为数组属性。

    有关示例,请参阅 augeasproviders.com,以及实现 augeas 提供程序 on github 的各种模块。

    【讨论】: