对于只有一个或两个属性发生变化的资源,我可以分别使用数组和哈希值。例如,如果我必须在不同的目录中创建文件,我可以将文件名和相应的路径存储在哈希中,并通过迭代哈希来应用它们。如果我有两个以上不同的属性,我如何存储和迭代这些属性?
例如,我正在尝试创建Active Directory组,我有五个属性,每个组的属性都不同,如下所示:
Group_Name Display Name Path Description GroupCategory
"My Support" "Support" "OU=Groups,OU=DEF,DC=xyz,DC=Com" "Some decription" Security
"Prod DBA" "DBA" "OU=Groups,OU=XYZ,DC=xyz,DC=Com" "Different description" Distribution
...
...
更新:根据建议,这里是代码:
[root@myhost] cat params.pp
$ad_groups = {
'Group_Prod' => {
path => 'OU=Groups,OU=PROD,DC=TEST,DC=COM',
displayname => 'Prod Support',
description => 'Prod Support',
},
'Group_App' => {
path => 'OU=Groups,OU=APP,DC=TEST,DC=COM',
displayname => 'App Support',
description => 'App Support',
},
}
$ad_groups_defaults = {
'ensure' => present,
'groupscope' => 'Global',
'groupcategory' => 'Security',
},
[root@myhost] cat create_groups.pp
class infra::ad::create_groups (
$ad_groups = $infra::params::ad_groups,
$ad_groups_defaults = $infra::params::ad_groups_defaults,
) inherits infra::params {
create_resources(windows_ad::group,$ad_groups,$ad_groups_defaults)
}
现在,当我尝试运行它时,我收到以下错误:
Could not retrieve catalog from remote server: Error 500 on SERVER: "message":"Server Error: Evaluation Error: Error while evaluating a Resource Statement, Windows_ad::Group[Group_Prod]: default expression for $groupname tries to illegally access not yet evaluated $groupname at /etc/puppetlabs/code/environments/production/modules/infra/manifests/ad/create_groups.pp:5 on node puppet.test.com","issue_kind":"RUNTIME_ERROR"}
现在,如果我还在每个哈希块中添加groupname
属性,则会解决错误。我想知道的是,如果我的组名与散列键相同(在本例中为Group_Prod
和Group_App
),那么我可以以某种方式将这些散列键本身用作groupname
没有在每个哈希块中添加groupname
属性?