简体   繁体   中英

reflection of erb variables

I'm using a puppet template, which does an erb interpretation of the template file. 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:

<% 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?

并不是很了解人偶模板,但是如果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. 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; that's how Puppet gets all that info in the first place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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