2011-03-29 27 views
2

的完整代碼在https://gist.github.com/c9815c1b19a36ed07ca5如何在puppet provider中創建ssh_authorized_key資源? (我強制刷新?)

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資源節點分類的它在某種程度上
  • 呼叫沖洗莫名其妙

我在做什麼錯?

回答

0

我評論了你的要點。

我相信這個自定義類型代碼對使用本地ssh_authorized_key類型有點過於樂觀。將資源硬編碼到類型代碼並忽略目錄內容是臨界濫用。

這將是審慎的清單來實現這個代替

$keys = { 'rimuhosting' => { 'id' => ... }, ... } 

define my_authorized_key($ensure = present) { 
    $data = $keys[$title] 
    $key_name = $data['email'] + "-" + $data['public_key_version'] + "-" + $data['user'] 
    ssh_authorized_key { 
    "$key_name": 
     ensure => $ensure, 
     type => 'ssh-rsa', 
     ... 
    } 
} 

而且因爲全有或全無,似乎是目標

class authorized_keys($ensure = present) { 
    $names = keys($keys) # <- function from puppetlabs-stdlib module 
    my_authorized_key { $names: ensure => $ensure } 
} 

參數類可以是fugly使用,如果你想走這條路,我強烈建議將它與Hiera結合起來。