我是Puppet的新手,并开始使用它我想学习如何pipe理系统用户。
我有几个用户,有共同的属性,所以我想我应该把事情排除在外。
经过一番斗争,这是我带来的:
define staff::ssh_key($user) { ssh_authorized_key { $name[name]: ensure => present, key => $name[key], type => "ssh-rsa", user => $user, require => File["/home/${user}/.ssh"], } } define staff($fullname, $ssh_keys, $shell = "/bin/bash") { user { $name: ensure => present, comment => "${fullname},,,", home => "/home/${name}", managehome => true, groups => ["users", "adm", "sudo"], shell => $shell, } file { "/home/${name}/.ssh": ensure => directory, mode => 0700, owner => $name, require => User[$name], } staff::ssh_key { $ssh_keys: user => $name, } }
然后我宣布这样的用户:
staff { "drdaeman": fullname => "Aleksey Zhukov", shell => "/bin/zsh", ssh_keys => [ { name => "desktop", key => "AAAA....6s=", } { name => "notebook", key => "AAAA....Q==", } ], }
暂时,我保存了这两个部分都保存到一个单一的文件,称为staff.pp 。 对于远程configuration,我已经把site.pp与以下内容:
node "foobar.example.org" { import "staff.pp" }
虽然一切似乎在当地正常工作,通过调用puppet apply staff.pp ,它远程使用时失败。 运行puppet agent --test给我一个错误:
err: Could not retrieve catalog from remote server: Could not intern from pson: Could not convert from pson: Could not find relationship source "Staff::Ssh_key[namenotebookkeyAAAA...Q==]" err: Could not retrieve catalog; skipping run
(如果是这样的话,我在Ubuntu上使用Puppet 2.7.14,来自apt.puppetlabs.com。)
所以,Puppet似乎并不喜欢散列作为资源名称,至less在数据通过networking传递时是如此。 有什么办法可以解决这个问题,而不是诉诸手工拷贝所有必须的ssh_authorized_key资源? (这对我的口味来说太冗长了)
请注意,在这种情况下,我可以通过使用简单file "/home/${name}/.ssh/authorized_keys": ... } ssh_authorized_key file "/home/${name}/.ssh/authorized_keys": ... } . ssh_authorized_key file "/home/${name}/.ssh/authorized_keys": ... }而不是ssh_authorized_key ,或者使用concat::fragment来解决这个问题。与其他类似情况一样,某些资源具有多个依赖资源,这些资源不易轻易归为单个文件。 相反,我正在寻找一些相对通用的方式来解决这个和类似的情况(如果有的话)。
您将需要使用create_resource而不是声明:
staff::ssh_key { $ssh_keys: user => $name, }
保留user => $ name的便利性:
Staff::Ssh_key { user => $name, } create_resources('staff::ssh_key', $ssh_keys)
在ssh_keys => {}}中将ssh_keys更改为散列而不是数组