Puppet Hiera-来自散列的变量
我在希拉真的很糟糕,只是我似乎不明白。我不知道这是否可行,但我想为我的类提供一个哈希,比如:Puppet Hiera-来自散列的变量,puppet,hiera,Puppet,Hiera,我在希拉真的很糟糕,只是我似乎不明白。我不知道这是否可行,但我想为我的类提供一个哈希,比如: modules::unit::filemode::config - /usr/bin/ls, root, root, 0775 modules::unit::filemode::config - /usr/bin/ls, root, root, 0775 把它映射到 file { "$filename": owner => $owner, group =&g
modules::unit::filemode::config
- /usr/bin/ls, root, root, 0775
modules::unit::filemode::config
- /usr/bin/ls, root, root, 0775
把它映射到
file { "$filename":
owner => $owner,
group => $group,
mode => $mode
}
我尝试过使用散列和$config.each
,但我似乎无法理解
有什么建议吗?:)
谢谢
我想为我的类提供一个散列,类似于:
modules::unit::filemode::config
- /usr/bin/ls, root, root, 0775
modules::unit::filemode::config
- /usr/bin/ls, root, root, 0775
这是无效的YAML,并且您似乎试图与keymodules::unit::filemode::config
关联的值看起来不像散列。散列将值与键相关联,那么键在哪里
从预期用途来看,我猜您想要的更像这样:
# The value is one hash with keys name, owner, group, and mode
modules::unit::filemode::config:
path: '/usr/bin/ls'
owner: 'root'
group: 'root'
mode: '0775'
# The value is hash of hashes; the outer hash has file names for keys,
# and the inner ones have keys owner, group, and mode
modules::unit::filemode::config2:
'/usr/bin/ls':
owner: 'root'
group: 'root'
mode: '0775'
'/maybe/another':
owner: 'luser'
group: 'root'
mode: '0644'
$config2.each |$path, $props| {
file { $path:
* => $props,
}
}
或者像这样:
# The value is one hash with keys name, owner, group, and mode
modules::unit::filemode::config:
path: '/usr/bin/ls'
owner: 'root'
group: 'root'
mode: '0775'
# The value is hash of hashes; the outer hash has file names for keys,
# and the inner ones have keys owner, group, and mode
modules::unit::filemode::config2:
'/usr/bin/ls':
owner: 'root'
group: 'root'
mode: '0775'
'/maybe/another':
owner: 'luser'
group: 'root'
mode: '0644'
$config2.each |$path, $props| {
file { $path:
* => $props,
}
}
其中任何一个都可以为类参数提供数据$modules::unit::filemode::config
:
class modules::unit::filemode(
Hash $config
) {
# ...
}
前一种数据样式为单个文件提供信息,通过键显式访问散列成员最有意义:
file { $config['path']:
owner => $config['owner'],
group => $config['group'],
mode => $config['mode'],
}
或者,由于我仔细选择了与文件
资源属性(包括路径
)名称匹配的哈希键,因此可以将其缩写为:
file { $config['path']:
* => $config,
}
在这种情况下,迭代成员没有多大意义,因为它们没有什么单独的意义,而且它们只是在语法上,而不是语义上,具有可比性
后一种数据布局允许提供关于多个文件的信息,外部散列的每个元素一个文件。这些外部成员在语义上是可比较的,对它们进行迭代是使用数据的一种可能方式,可能类似于:
# The value is one hash with keys name, owner, group, and mode
modules::unit::filemode::config:
path: '/usr/bin/ls'
owner: 'root'
group: 'root'
mode: '0775'
# The value is hash of hashes; the outer hash has file names for keys,
# and the inner ones have keys owner, group, and mode
modules::unit::filemode::config2:
'/usr/bin/ls':
owner: 'root'
group: 'root'
mode: '0775'
'/maybe/another':
owner: 'luser'
group: 'root'
mode: '0644'
$config2.each |$path, $props| {
file { $path:
* => $props,
}
}
它声明了与(外部)散列的每个元素对应的文件资源