函数参考-在puppet中创建_资源

函数参考-在puppet中创建_资源,puppet,Puppet,提及 阅读此函数的说明create\u resources,但不确定create\u resources(user,$myusers) 它是否使用指定的uid、gid和组创建两个用户nick和dan 更新: 网上的一些解释 Listing 12-79. Hiera lookup of sysadmin hash root@puppet-master-hiera-ubuntu:/etc/puppet/data# hiera sysadmins {"spencer"=>{"uid"=>1

提及

阅读此函数的说明
create\u resources
,但不确定
create\u resources(user,$myusers)

它是否使用指定的uid、gid和组创建两个用户
nick
dan

更新: 网上的一些解释

Listing 12-79. Hiera lookup of sysadmin hash
root@puppet-master-hiera-ubuntu:/etc/puppet/data# hiera sysadmins
{"spencer"=>{"uid"=>1861, "groups"=>"root", "gid"=>300}, "william"=>{"uid"=>11254,
"groups"=>"root", "gid"=>300}}

   Now we can use a function called create_resources() to generate Puppet resources from this hash, as shown in

Listing 12-80. create_resources example

$sysadmins = hiera('sysadmins')

create_resources(user, $sysadmins)

    Listing 12-81 shows the output.

Listing 12-81. Applying the create_resources example from Listing 12-80

root@puppet-master-hiera-ubuntu:/etc/puppet# puppet apply create_resources.pp
Notice: Compiled catalog for puppet-master-hiera-ubuntu.green.gah in environment production in
0.11 seconds
Notice: /User[spencer]/ensure: created
Notice: /User[william]/ensure: created
Notice: Finished catalog run in 0.32 seconds

我无法在我的环境中正确地设置和证明它,但上面的示例给出了答案,它确实使用
create\u resources
函数中的哈希创建了用户帐户。

create\u resources
将只映射

# A hash of user resources:
$myusers = {
  'nick' => { uid    => '1330',
              gid    => allstaff,
              groups => ['developers', 'operations', 'release'], },
  'dan'  => { uid    => '1308',
              gid    => allstaff,
              groups => ['developers', 'prosvc', 'release'], },
}

create_resources(user, $myusers)
进入

所以这些用户将被传递给用户提供者。您可以使用您的配方轻松地创建一个users.pp文件,并使用
puppet apply--noop
对其进行测试:

# puppet apply --noop users.pp 
Notice: Compiled catalog for yourfqdn in environment production in 0.15 seconds
Notice: /Stage[main]/Main/User[nick]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Main/User[dan]/ensure: current_value absent, should be present (noop)

请注意,如果用户已经存在,puppet apply在映射并传递给用户提供程序后不会执行任何操作,我该如何使用它?你能给我一个样品吗?例如,我需要创建用户(nick)。您可以像使用任何其他清单一样使用函数调用—通过
puppet master
puppet apply
。您的意思是,使用
create_resources()
,在我应用pp文件后,将创建两个用户(nick和dan)(如果以前没有创建)?就是这样。我已经在
puppet apply--noop的答案后面添加了结果
  user{'nick':
    uid    => '1330',
    gid    => allstaff,
    groups => ['developers', 'operations', 'release'], },
  }
  user{'dan':
    uid    => '1308',
    gid    => allstaff,
    groups => ['developers', 'prosvc', 'release'], },
  }
# puppet apply --noop users.pp 
Notice: Compiled catalog for yourfqdn in environment production in 0.15 seconds
Notice: /Stage[main]/Main/User[nick]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Main/User[dan]/ensure: current_value absent, should be present (noop)