英文:
Create new array from hiera_hash, but avoid nested data
问题
我有一个看起来像这样的 hiera_hash:
signalfx_custom_receivers:
smartagent/http1:
type: http
host: "es.mydomain.tv"
useHTTPS: true
smartagent/http2:
type: http
host: "es.other.tv"
useHTTPS: true
smartagent/http3:
type: http
host: "pmd-akamai.cdn.mydomain.tv"
useHTTPS: true
我试图从中生成一个数组以在其他地方使用。这个数组应该只包含 smartagent 的值,所以应该是这样的:
[smartagent/http1, smartagent/http2, smartagent/http3]
我尝试过以下方法:
$signalfx_custom_pipeline = Array($signalfx_custom_receivers)
然而,这包括了所有嵌套的键/值,最终看起来像这样:
[["smartagent/http1", {"type"="http", "host"="es.mydomain.tv", "useHTTPS"=true}], ["smartagent/http2", {"type"="http", "host"="es.other.tv", "useHTTPS"=true}], ["smartagent/http3", {"type"="http", "host"="pmd-akamai.cdn.mydomain.tv", "useHTTPS"=true}]]
如何生成一个数组,但避免添加这些嵌套值?
英文:
I have a hiera_hash that looks like this:
signalfx_custom_receivers:
smartagent/http1:
type: http
host: "es.mydomain.tv"
useHTTPS: true
smartagent/http2:
type: http
host: "es.other.tv"
useHTTPS: true
smartagent/http3:
type: http
host: "pmd-akamai.cdn.mydomain.tv"
useHTTPS: true
I'm trying to generate an array from this to use elsewhere. The array should only contain smartagent values, so should looks like this:
[smartagent/http1, smartagent/http2, smartagent/http3]
I've tried the following:
$signalfx_custom_pipeline = Array($signalfx_custom_receivers)
However, this includes all of the nested key/values, and ends up looking like this:
[["smartagent/http1", {"type"=>"http", "host"=>"es.mydomain.tv", "useHTTPS"=>true}], ["smartagent/http2", {"type"=>"http", "host"=>"es.other.tv", "useHTTPS"=>true}], ["smartagent/http3", {"type"=>"http", "host"=>"pmd-akamai.cdn.mydomain.tv", "useHTTPS"=>true}]]
How can I generate an array, but avoid adding these nested values?
答案1
得分: 2
我试图从这里生成一个数组以在其他地方使用。数组应仅包含smartagent值。
也就是说,哈希表的键。提取这些键正是内置的keys()
函数所做的事情:
$signalfx_custom_pipeline = keys($signalfx_custom_receivers)
# 或者
$signalfx_custom_pipeline = $signalfx_custom_receivers.keys()
这两种形式的行为完全相同,但个人而言,在这种情况下,我觉得第二种更清晰。
英文:
> I'm trying to generate an array from this to use elsewhere. The array should only contain smartagent values
That is, the keys of the hash. Extracting these is exactly what the built-in keys()
function does:
$signalfx_custom_pipeline = keys($signalfx_custom_receivers)
# or
$signalfx_custom_pipeline = $signalfx_custom_receivers.keys()
The two forms behave identically, but personally, I find the second clearer in this case.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论