[英]Function Reference - create_resources in puppet
請參閱https://docs.puppetlabs.com/references/latest/function.html#createresources
# 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)
閱讀此函數的說明create_resources
,但不確定在create_resources(user, $myusers)
之后會create_resources(user, $myusers)
什么結果
它是否使用指定的uid,gid和groups創建兩個用戶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_resources
函數中使用哈希創建用戶帳戶。
create_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)
成
user{'nick':
uid => '1330',
gid => allstaff,
groups => ['developers', 'operations', 'release'], },
}
user{'dan':
uid => '1308',
gid => allstaff,
groups => ['developers', 'prosvc', 'release'], },
}
因此,這些用戶將被傳遞給用戶提供者。 您可以使用配方輕松地對其進行測試,以創建一個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不會做任何事情
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.