On 23/04/18 08:33, Johan De Wit wrote:
first notify, the index should be quoted ....
notify { "OS: $facts['os']['family']": }
That us unfortunately wrong - it will produce the entire $facts hash as
a string followed by the *text* "['os']['family']".
The correct way is to write:
notify { "OS: ${facts['os']['family']}": }
Or, if you like:
notify { "OS: ${facts.dig('os', 'family')}
(or by using the "pick()" function from stdlib which is similar to "dig()")
Best,
- henrik
Grts
-----Original message-----
*From:* Arnau <[email protected]>
*Sent:* Friday 20th April 2018 14:22
*To:* [email protected]
*Subject:* [Puppet Users] Accessgin facts hash from manifests
Hi all,
I'm having the first experiences with puppet 5 & facter 3
In old puppet versions I tend to add debug messages like:
notify { "OS : {::osfamily}: }
and it usually worked.
According to
https://puppet.com/docs/puppet/5.3/lang_facts_and_builtin_vars.html#accessing-facts-from-puppet-code
<https://puppet.com/docs/puppet/5.3/lang_facts_and_builtin_vars.html#accessing-facts-from-puppet-code>
I can still access the facts using the old way, but it recommend to
use the facts has, so the new code should look like:
notify { "OS: $facts[os][family]": }
But when I do that I get the full list of facts and [os][family] at
the bottom:
Notice: OS: {agent_specified_environment => test, aio_agent_version
=> 5.5.1, architecture => x86_64, augeas => {version => 1.10.1}
[.... TONS OF FACTS ...] clientversion => 5.5.1, clientnoop =>
false}['os]['family']"
If I use the same syntax in a conditiona statement:
if $facts['os']['family'] == 'RedHat' {
notify { "I'm a RedHat": }
}
then it works:
Notice: /Stage[main]/Common::Yumrepos/Notify[I'm a RedHat]/message:
defined 'message' as 'I\'m a RedHat'
So, what's wrong with the above notify?
TIA,
Arnau
--
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 [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/CAM69jx_sAms0%3Da%2B5MhHBtnydtPKsUDeAAcera8tXSsaANaTchA%40mail.gmail.com
<https://groups.google.com/d/msgid/puppet-users/CAM69jx_sAms0%3Da%2B5MhHBtnydtPKsUDeAAcera8tXSsaANaTchA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/zarafa.5add7e24.7f1a.78dfd5c52ec466fa%40zarafa7.open-future.be
<https://groups.google.com/d/msgid/puppet-users/zarafa.5add7e24.7f1a.78dfd5c52ec466fa%40zarafa7.open-future.be?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/
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/pbk789%242rk%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.