create_resources 函数和 puppet ENC

create_resources 函数和 puppet ENC

/etc/puppet/manifests/classes/users.pp

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)

}

/etc/puppet/manifests/site.pp

"classes/*.pp"
node default{}

ENC 的 yaml 输出

---
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

我究竟做错了什么?

答案1

兄弟,你的“require => resource”是错误的。

所需资源以首字母大写来表示,如文件、用户..而不是文件、用户。

答案2

我猜想变量 $user 包含不正确的哈希值

  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'])

相关内容