On 08/29, [email protected] wrote:
> Does foreman store facts as hash?

No, but they are presented as a hash when calling `@host.facts`. I saw
it poking around with `foreman-rake console`:

irb(main):003:0> Host.first.facts.class
=> Hash

> Because when i queried the node using api to gather facts, i see that the
> facts hash that i uploaded is now null:

Can you share the facts hash that you have uploaded? If it had multiple
levels, they are stored as strings like you posted.

If you want to iterate through the actual FactValue object, it might
make it simple for you:

fact_values = FactValue.search_for("host = #{Host.first.fqdn}")

Or if you want to get ONLY the values with an actual value (so the ones
that are 'leaves' of the tree):

FactValue.search_for("host = #{Host.first.fqdn}").where.not(:value  =>
nil)

>
>             "kickstart_repos": null,
>             "kickstart_repos::base": null,
>
> I see that it has created the child variables out of the hash.
>
> "kickstart_repos::base::baseurl":
> "http://10.230.1.106:8090/centos/7/os/x86_64/";,
>
> This makes the template writing really difficult, because i will have to
> statically mention each key of the facts hash that i have uploaded, in the
> templates.
>
> One of the advantages of hash is that it could be dynamic, and we should be
> able to iterate over whichever keys it contains.
>
> How do i make foreman store the facts as a hash and not function as above?
>
>
> On Tuesday, August 29, 2017 at 4:31:25 PM UTC-4, [email protected] wrote:
> >
> > I am trying to find a way to iterate over facts hash with 'each' function.
> > But i get this error:
> >
> > ' There was an error rendering the CentOS_test1 template: undefined method
> > `each' for nil:NilClass'
> >
> > Safe mode rendering is off.
> >
> > How do i iterate over nested structured facts/facts hash in provision
> > templates in foreman?
> >
> > For example - the following does not work.
> >
> > <% @host.facts_hash['kickstart_repos::base'].each do |k| %>
> > <%= k %>: <%= @host.facts_hash[k] %>
> > <% end %>
> >
> > Is there a restriction on what ruby methods i can use inside templates?
> > The same template works fine in puppet/with ruby.
> >
> > I tried searching for examples but could not find any.
> > The documentation mentions that :
> >
> > @host.facts: Contains a hash of facts from Facter/Ohai etc. (1.7.2+)
> > @host.facts_hash : Contains a hash of facts from Facter/Ohai etc. (only
> > works if safemode_render=false)
> >
> > I assume the above means, that both those variables are hashes and can be
> > iterated?
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Foreman users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/foreman-users.
> For more options, visit https://groups.google.com/d/optout.


--
Daniel Lobato Garcia

@dLobatog
blog.daniellobato.me
daniellobato.me

GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30
Keybase: https://keybase.io/elobato

-- 
You received this message because you are subscribed to the Google Groups 
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: PGP signature

Reply via email to