search facts by regex

78 views
Skip to first unread message

Alex Bogatu

unread,
Feb 27, 2015, 3:33:23 AM2/27/15
to puppet...@googlegroups.com
Hello!
I spent the last couple of days trying to find a good way to search facts specific to some node based on ragex. For example, in my puppet manifest i need a way to check if there are facts whose names (not values) match a specific regex.  Is there anyone who had this problem before? I know that it might be done using inline ruby code, but i wonder if there is no other solution.

Henrik Lindberg

unread,
Feb 27, 2015, 9:08:46 AM2/27/15
to puppet...@googlegroups.com
See here:
https://docs.puppetlabs.com/puppet/latest/reference/lang_facts_and_builtin_vars.html#the-factsfactname-hash

Then using the standard lib function keys() on $facts to get an array of
the keys. You can then use the in operator to search.
Alternatively use the standard lib function has_key($facts).

If you are using parser=future you can also iterate over the hash's keys
and values directly.

- henrik

> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/f4c9d059-c989-4ea4-86f6-418e786f2f9b%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/f4c9d059-c989-4ea4-86f6-418e786f2f9b%40googlegroups..com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Reply all
Reply to author
Forward
0 new messages