class users { define add_user($uname, $comment, $home, $shell, $uid, $gid, $password) { # Create the user. This is where most of the magic happens. user { "$uname": username => $uname, ensure => present, comment => "$comment", home => "$home", shell => "$shell", uid => "$uid", password => "$password", gid => "$gid" } file { "/home/$uname/": ensure => directory, owner => $uname, group => $gid, mode => 750, require => [ user[$uname] ] } # And a place with the right permissions for the SSH related configs file { "/home/$uname/.ssh": ensure => directory, owner => $uname, group => $gid, mode => 700, require => file["/home/$uname/"] } # Now make sure that the ssh key authorized files is around file { "/home/$uname/.ssh/authorized_keys": ensure => present, owner => $uname, group => $gid, mode => 600, require => file["/home/$uname/.ssh"] } } create_resources(users::add_user, $users) }
"classes/*.pp" node default{}
--- classes: users: jeckman: comment: Jack gid: 100 home: /home/jeckman name: jeckman password: $1$hash shell: /bin/bash uid: 10146 saga: comment: Arun gid: 100 home: /home/saga name: saga password: $1$hash shell: /bin/bash uid: 70960 sandipb: comment: Sandip gid: 100 home: /home/sandipb name: sandipb password: $1$hash shell: /bin/bash uid: 24838 vartika: comment: Vartika gid: 100 home: /home/vartika name: vartika password: $1$hash shell: /bin/bash uid: 38599
saga@battleoffer-dr ~]$ sudo puppet master --compile=darkguard-dr.eglbp.corp.company.com --debug --verbose info: Not using expired node for darkguard-dr.eglbp.corp.company.com from cache; expired at Thu Jul 19 01:21:25 +0530 2012 debug: Executing '/etc/puppet/manifests/enc/puppet_enc.py darkguard-dr.eglbp.corp.company.com' info: Caching node for darkguard-dr.eglbp.corp.company.com debug: importing '/etc/puppet/manifests/classes/users.pp' in environment production warning: Deprecation notice: Resource references should now be capitalized on line 29 in file /etc/puppet/manifests/classes/ users.pp warning: Deprecation notice: Resource references should now be capitalized on line 38 in file /etc/puppet/manifests/classes/ users.pp warning: Deprecation notice: Resource references should now be capitalized on line 49 in file /etc/puppet/manifests/classes/ users.pp err: Invalid parameter sandipb on node darkguard-dr.eglbp.corp.company.com Invalid parameter sandipb on node darkguard-dr.eglbp.corp.company.com
我究竟做错了什么?
老兄,你的'require =>资源'是错误的。
需要使用第一个字母CAPS调用资源,如文件,用户..不是文件,用户。
我想象variables$用户包含不正确的哈希做
file {'/tmp/users.yaml': content => inline_template("<%= dbq %><%= YAML::dump(users) %>"), }
并检查输出。 它应该看起来像:
jeckman: comment: Jack gid: 100 home: /home/jeckman name: jeckman password: $1$hash shell: /bin/bash uid: 10146 saga: comment: Arun gid: 100 home: /home/saga name: saga password: $1$hash shell: /bin/bash uid: 70960
如果没有,你传递坏散列
你可能想尝试:
create_resources(users::add_user, $users['users'])