如何在puppet ERB模板中处理yaml数组?

如何在puppet ERB模板中处理yaml数组?,yaml,puppet,erb,hiera,Yaml,Puppet,Erb,Hiera,我有一些hiera数据,如下所示: netapp_nfs_shares: - 10.199.1.34:/os_cloud - 127.0.0.2:/example # This file was generated from nfs-shares.conf.erb by puppet <% Array(@netapp_nfs_shares).each do |line| -%> <%= line %> <% end -%> # This file

我有一些hiera数据,如下所示:

netapp_nfs_shares:
  - 10.199.1.34:/os_cloud
  - 127.0.0.2:/example
# This file was generated from nfs-shares.conf.erb by puppet
<% Array(@netapp_nfs_shares).each do |line| -%>
<%= line %>
<% end -%>
# This file was generated from nfs-shares.conf.erb by puppet
["10.199.1.34:/os_cloud", "127.0.0.2:/example"]
# This file was generated from nfs-shares.conf.erb by puppet
10.199.1.34:/os_cloud
127.0.0.2:/example
这将作为参数传递给我的类,并在如下所示的erb模板文件中使用:

netapp_nfs_shares:
  - 10.199.1.34:/os_cloud
  - 127.0.0.2:/example
# This file was generated from nfs-shares.conf.erb by puppet
<% Array(@netapp_nfs_shares).each do |line| -%>
<%= line %>
<% end -%>
# This file was generated from nfs-shares.conf.erb by puppet
["10.199.1.34:/os_cloud", "127.0.0.2:/example"]
# This file was generated from nfs-shares.conf.erb by puppet
10.199.1.34:/os_cloud
127.0.0.2:/example
我希望我能得到这样一个文件:

netapp_nfs_shares:
  - 10.199.1.34:/os_cloud
  - 127.0.0.2:/example
# This file was generated from nfs-shares.conf.erb by puppet
<% Array(@netapp_nfs_shares).each do |line| -%>
<%= line %>
<% end -%>
# This file was generated from nfs-shares.conf.erb by puppet
["10.199.1.34:/os_cloud", "127.0.0.2:/example"]
# This file was generated from nfs-shares.conf.erb by puppet
10.199.1.34:/os_cloud
127.0.0.2:/example

我怀疑我写的模板有问题。我做错了什么?

像这样的事情应该可以做到:

<% @netapp_nfs_shares.each do |line| -%>
<%= line %>
<% end -%>


我怀疑使用Array()会将数组包装到另一个数组中。

类似这样的操作应该可以做到:

<% @netapp_nfs_shares.each do |line| -%>
<%= line %>
<% end -%>

我怀疑使用Array()是在将数组包装到另一个数组中。

您的Hiera数据文件中只有一个YAML数组。您不需要做任何特殊的操作来将其转换为傀儡数组——当Hiera检索它时,无论是在自动数据绑定(您的案例)期间,还是当您使用
Hiera()
函数手动检索它时,都会自动发生这种情况。您的Hiera数据文件中只有一个YAML数组。您不需要做任何特殊的操作来将其转换为傀儡数组——当Hiera检索它时,无论是在自动数据绑定(您的案例)期间,还是在您使用
Hiera()
函数手动检索它时,都会自动发生这种情况。