简体   繁体   English

erb变量的反映

[英]reflection of erb variables

I'm using a puppet template, which does an erb interpretation of the template file. 我正在使用人偶模板,该模板对模板文件进行erb解释。 I'd like to know all the variables available to me, however, there are variables available (eg, fqdn) that are not listed by any of the reflection methods I'm aware of, specifically, none of these: 我想知道所有可用的变量,但是,有些变量(例如fqdn)没有被我知道的任何反射方法列出,具体而言,这些都不是:

<% Module.constants.each do |v| %># module constant: <%= v %>
<% end %>
<% Kernel.local_variables.each do |v| %># local variable: <%= v %>
<% end %>
<% Kernel.instance_variables.each do |v| %># instance variable: <%= v %>
<% end %>
<% Module.class_variables.each do |v| %># class variable: <%= v %>
<% end %>
<% Kernel.global_variables.each do |v| %># global variable: <%= v %>
<% end %>

Is there an extra reflection method for erb that will reveal these to me? 是否有一种额外的erb反射方法可以将这些信息显示给我?

并不是很了解人偶模板,但是如果fqdn是局部变量,则调用local_variables (如self.local_variables )应该显示它。

I don't know as much as I'd like to about erb's built-in means of reflection, but with Puppet, I think the hash returned by scope.to_hash is probably what you want. 我对erb的内置反射方式不甚了解,但是对于Puppet,我认为scope.to_hash返回的哈希可能正是您想要的。 From the templating reference : 模板参考

<% scope.to_hash.keys.each do |k| -%>
<%= k %>
<% end -%>

Alternately, if you just want a one-time look at the variables the agent node supplies, you can run facter on the node; 另外,如果您只想一次性查看代理节点提供的变量,则可以在该节点上运行facter that's how Puppet gets all that info in the first place. 这就是Puppet首先获取所有信息的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM