Puppet4 $facts syntax

39 views
Skip to first unread message

Poil

unread,
Mar 10, 2017, 12:05:26 PM3/10/17
to puppet...@googlegroups.com
Hi,

In the style guide we have $facts[::operatingsystem]

In all others documentation we have $facts['fact_name']

So which one is the good one ? Do we really need to scope inside
$facts[::scope] ?

Best regards,

R.I.Pienaar

unread,
Mar 10, 2017, 1:02:24 PM3/10/17
to puppet...@googlegroups.com
Easily answered:

% puppet apply -e 'notice($facts[::operatingsystem])'
Notice: Scope(Class[main]):

vs:

% puppet apply -e 'notice($facts["operatingsystem"])'
Notice: Scope(Class[main]): CentOS

the first is just wrong

--
R.I.Pienaar / www.devco.net / @ripienaar

Dirk Heinrichs

unread,
Mar 10, 2017, 1:06:38 PM3/10/17
to puppet...@googlegroups.com
Am 10.03.2017 um 14:02 schrieb R.I.Pienaar:

the first is just wrong

OTOH, I mostly use $::facts['fact_name'].

Bye...

    Dirk
--
Dirk Heinrichs
Senior Systems Engineer, Delivery Pipeline
OpenTextTM Discovery | Recommind
Email: dirk.he...@recommind.com
Website: www.recommind.de

Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach

Vertretungsberechtigte Geschäftsführer John Marshall Doolittle, Gordon Davies, Roger Illing, Registergericht Amtsgericht Bonn, Registernummer HRB 10646

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.

R.I.Pienaar

unread,
Mar 10, 2017, 1:10:34 PM3/10/17
to puppet...@googlegroups.com


On Fri, Mar 10, 2017, at 14:06, Dirk Heinrichs wrote:
> Am 10.03.2017 um 14:02 schrieb R.I.Pienaar:
>
> > the first is just wrong
>
> OTOH, I mostly use $::facts['fact_name'].

this is not needed.

The reason you use $::foo is because of the problem here:

$foo = "top"
class x($foo="class") {
notice($foo)
notice($::foo)
}

include x

this produce:

Notice: Scope(Class[X]): class
Notice: Scope(Class[X]): top

you need to guard against the accidental $foo which used to be much
worse with dynamic scope, so the code got littered with all this ::
rubbish.

$facts is globally reserved

class x {
$facts = {}
}

include x

Error: Evaluation Error: Error while evaluating a '=' expression,
Attempt to assign to a reserved variable name: 'facts'

You can never cause the problem that raised the need for $::facts to
exist, you can just use $facts and it's all sweet and

In general with Puppet 4 the needs for all the :: stuff is almost all
gone

Dirk Heinrichs

unread,
Mar 10, 2017, 1:14:10 PM3/10/17
to puppet...@googlegroups.com
On 10.03.2017 14:10, R.I.Pienaar wrote:

You can never cause the problem that raised the need for $::facts to exist, you can just use $facts and it's all sweet and
In general with Puppet 4 the needs for all the :: stuff is almost all gone

Ah, good to know. Thanks for clarifying.

Poil

unread,
Mar 10, 2017, 1:25:19 PM3/10/17
to puppet...@googlegroups.com, R.I.Pienaar
@all, thanks :)
Reply all
Reply to author
Forward
0 new messages