我本周开始学习 puppet ,并努力实现用户对/etc/ssh/sudo_authorized_keys
的密钥。
我有一个关键字在sudo_users.yaml
中的用户词典:
core::sudo_users_keys:
kate:
keys:
key1:
type: "ssh-ed25519"
key: "AAAAC3N..."
john:
keys:
key1:
type: "ssh-ed25519"
key: "AAAAC..."
marvin:
keys:
key1:
type: "ssh-ed25519"
key: "AAAAC3Nza..."
然后,我在sudokeys.pp
文件中创建此文件:
class core::sudokeys {
file { "/etc/ssh/sudo_authorized_keys":
ensure => file,
mode => "0440",
content => template("core/sudo_authorized_keys.erb"),
}
如您所见,我希望使用迭代来实现模板。这是我当前的模板:
<%- scope['core::sudo_users_keys'].each | user | -%>
{
<%- if user[1] -%>
<%- $user[1]['keys'].each do | key | -%>
<%= $key[1]['type'] $key[1]['key'] -%>
<%- end end -%>
}
<%- end -%>
我有相同的字典,具有指向ssh的id_rsa键,并使用如下交互。它非常适合sshAuthorizedkey,但在本例中,我可以通过向/etc/ssh/sudo_authorized_keys
添加密钥来使用它。这就是为什么我决定使用模板,只在sudo_authorized_keys
文件中注入密钥。
class core::sshkeys {
lookup("core::sudo_users_keys").each | $user | {
if $user[1] {
$user[1]["keys"].each | $key | {
ssh_authorized_key { "${user[0]}-${key[0]}":
ensure => present,
user => $user[0],
type => $key[1]["type"],
key => $key[1]["key"],
}
}
}
}
}
puppet 文档不包括这种更复杂的迭代,我感觉就像在雾中徘徊。
目前,我在部署模板时收到这个错误,但我觉得我准备模板的方式不会像我想要的那样工作。
Internal Server Error: org.jruby.exceptions.SyntaxError: (SyntaxError) /etc/puppetlabs/code/environments/test/modules/core/templates/sudo_authorized_keys.erb:2: syntax error, unexpected tSTRING_BEG
_erbout.<< " {\n".freeze
^
我将感谢任何关于模板建设的建议。我应该做什么更改才能使它工作并仅提取type
和key
值?
暂无答案!
目前还没有任何答案,快来回答吧!