【问题标题】:Translate Augeas into Puppet speak Augeas将 Augeas 翻译成 Puppet 说 Augeas
【发布时间】:2016-11-28 22:26:34
【问题描述】:

使用 puppet 的 augeas 功能我想修改配置文件:

/etc/ssh/sshd_config

在没有 puppet 的情况下,我使用 Augeas 的“augtool”进行了实验,发现有几行似乎可行:

augtool> set /files/etc/ssh/sshd_config/Match[1]/Condition/User "bill","ben"   
augtool> set /files/etc/ssh/sshd_config/Match/Settings/PasswordAuthentication "no" 
augtool> save

虽然它看起来工作正常,但我真的不明白 [1] 在这里的用途。

我尝试将这些台词放入 Puppet,但没有成功:

augeas { "sshd_config":
  context => "/files/etc/ssh/sshd_config",
  changes => [
  'set Match[1]/Condition/User "bill","ben"',
  'set Settings/PasswordAuthentication "no"',
  ],     
}

它给出了错误: 错误:/Stage[main]/Samipermissions/Augeas[sshd_config]:无法评估:保存失败,请参阅调试

在调试模式下运行 Puppet 告诉我同样的事情。

有人知道这是如何工作的吗?

谢谢你 m0dlx。 您的回答使我摆脱了遇到的错误,但是我认为我仍然对匹配数组感到有些迷茫。使用“augtool”我可以做到以下几点:

set /files/etc/ssh/sshd_config/Match[1]/Condition/User "neil","nigel"
set /files/etc/ssh/sshd_config/Match[1]/Settings/PasswordAuthentication "no" 
set /files/etc/ssh/sshd_config/Match[2]/Condition/User "yvonne","yvette"
set /files/etc/ssh/sshd_config/Match[2]/Settings/PasswordAuthentication "yes" 

在配置文件中显示为:

Match User neil,nigel
  PasswordAuthentication no
Match User yvonne,yvette
  PasswordAuthentication yes

这是完美的。我将其翻译为 Puppet:

  augeas { "sshd_config":
    context => "/files/etc/ssh/sshd_config",
    changes => [
      'set Match[1]/Condition/User "neil","nigel"',
      'set Match[1]/Settings/PasswordAuthentication "no"',
      'set Match[2]/Condition/User "yvonne","yvette"',
      'set Match[2]/Settings/PasswordAuthentication "yes"',
    ],
  }

但是配置文件中的结果却大不相同:

Match User neil
  PasswordAuthentication no
Match User yvonne
  PasswordAuthentication yes

【问题讨论】:

    标签: puppet augeas


    【解决方案1】:

    m0dlx 的回答和后来的评论让我想到了以下完美的方法:

      augeas { "sshd_config":
        context => "/files/etc/ssh/sshd_config",
        changes => [
          'set Match[1]/Condition/User "neil,nigel"',
          'set Match[1]/Settings/PasswordAuthentication "no"',
          'set Match[2]/Condition/User "yvonne,yvette"',
          'set Match[2]/Settings/PasswordAuthentication "yes"',
        ],
      }
    

    谢谢m0dlx。

    【讨论】:

      【解决方案2】:

      虽然它看起来工作正常,但我真的不明白 [1] 在这里的用途。

      [1] 就像访问一个数组元素,如果有多个,则表示您要访问第一个 Match 条目。

      'set Settings/PasswordAuthentication "no"',

      您在 augtool 测试中错过了前导 Match/,这可能会导致 Puppet 的保存失败。

      如果您仍有问题,请在问题中包含 Puppet 的完整调试输出。

      【讨论】:

      • 另外,augeasproviders_ssh 有一个 sshd_config 提供程序可以很好地管理条件:forge.puppet.com/herculesteam/…
      • 感谢 Raphink,但我正在尝试掌握 Augeas,而不是使用导入的模块
      • 谢谢你 m0dlx,这是一个很大的帮助,遗憾的是它并没有让我完全到达我需要的地方。考虑到您的帮助,我已添加到问题中
      • 尝试从名称中删除中间的引号,例如'set Match[1]/Condition/User "neil,nigel"',
      • m0dlx 你是明星。非常感谢 。在您的回答和评论之间,您对我的帮助很大,谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 2018-10-23
      相关资源
      最近更新 更多