2016-07-25 21 views
1

使用木偶的augeas能力,我想修改配置文件:翻译Augeas成木偶说话Augeas

/etc/ssh/sshd_config 

没有傀儡,我使用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]在这里服务的目的。

我试过没有成功把这些线木偶到:

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

它给人的错误: 错误:/舞台[主]/Samipermissions/Augeas [sshd_config中]:无法评价:保存失败,请参阅调试

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

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

谢谢你m0dlx。 你的答案让我感动了过去的错误,但是我觉得我仍然有点迷失于Matches数组。使用 “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 

这是完美的。我翻译这个木偶为:

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 

回答

2

Although it seems to work OK, I don't really understand what purpose the [1] serves here.

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

'set Settings/PasswordAuthentication "no"',

你已经错过了断,你在augtool测试了领先Match/,这可能会导致从木偶保存失败。

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

+0

另外,[augeasproviders_ssh](https://forge.puppet.com/herculesteam/augeasproviders_ssh)有一个'sshd_config'提供程序,它可以很好地管理条件:https://forge.puppet.com/herculesteam/augeasproviders_ssh#manage -entry-in-a-match-block –

+0

谢谢拉斐克,但我试图与Augeas握手而不是使用进口模块 – user835745

+0

谢谢m0dlx,这是一个很大的帮助,可惜它没有让我相当满意我需要成为。我已将您的帮助添加到问题 – user835745

0

答案,并从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。