完整代码在https://gist.github.com/c9815c1b19a36ed07ca5
在nodes.pp
我有
node 'random.brighterplanet.com' {
$deploy_user = 'www-data'
include secured_by_authorized_keys
include logs_in_as_deploy
}
在modules/logs_in_as_deploy/manifests/logs_in_as_deploy.pp
我有
class logs_in_as_deploy {
access_via_authorized_key { $deploy_user:
ensure => present
}
}
在modules/secured_by_authorized_keys/lib/puppet/provider/authorized_keys.rb
我有
# [...]
def to_ssh_authorized_key(name, ensure_status)
k = Puppet::Type.type(:ssh_authorized_key).new :name => id(name), :ensure => ensure_status, :key => public_key, :type => 'ssh-rsa', :user => name
k.provider.create
k
end
# [...]
Puppet::Type.type(:access_via_authorized_key).provide(:authorized_keys) do
# [...]
def create
ks = AuthorizedParty.all.map do |authorized_party|
authorized_party.to_ssh_authorized_key resource[:name], :present
end
end
# [...]
我懂了
# puppet --debug /etc/puppet/manifests/site.pp
[...]
notice: /Stage[main]/Logs_in_as_deploy/Access_via_authorized_key[www-data]/ensure: created
debug: Finishing transaction -611364608
debug: Storing state
debug: Stored state in 0.01 seconds
notice: Finished catalog run in 2221.41 seconds
但是没有任何东西写入authorized_keys
文件。我想我要么必须
- 以某种方式将内置
ssh_authorized_key
资源添加到节点目录 - 以某种方式调用它
我究竟做错了什么?