Inside a custom function, how do you if noop is enabled ?

150 views
Skip to first unread message

Frédéric Lespez

unread,
Sep 20, 2015, 12:58:30 PM9/20/15
to Puppet Users
In a manifest, you can test the built-in variable $clientnoop to know if puppet agent runs in noop mode or not.
See https://docs.puppetlabs.com/puppet/latest/reference/lang_facts_and_builtin_vars.html#puppet-agent-facts

But inside a custom function, how can you know if noop is enabled or not ?
It seems that you cannot access the built-in variable $clientnoop inside function.

Any clues ?

Regards,
Fred

Henrik Lindberg

unread,
Sep 21, 2015, 9:15:02 AM9/21/15
to puppet...@googlegroups.com
In the 3.x function API use:

lookupvar('varname')

In the 4.x function API use:

closure_scope.lookupvar('varname')

Here is the specification for the 4.x API.
https://github.com/puppetlabs/puppet-specifications/blob/master/language/func-api.md

Note that closure_scope in the 4.x API does not give access to the
variables in the scope calling the function, but it does provide access
to global variables.

Also consider looking up the $facts hash instead of directly looking up
individual facts like $clientnoop. This to be future proof. (See the
link you posted regarding details).

Regards
- henrik


> Regards,
> Fred
>
> --
> 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/325d8144-5836-4581-8cd2-3f5e3c44ce95%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/325d8144-5836-4581-8cd2-3f5e3c44ce95%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/

Frédéric Lespez

unread,
Sep 21, 2015, 4:34:22 PM9/21/15
to Puppet Users

In the 3.x function API use:

   lookupvar('varname')

In the 4.x function API use:

   closure_scope.lookupvar('varname')

Here is the specification for the 4.x API.
https://github.com/puppetlabs/puppet-specifications/blob/master/language/func-api.md
Thank Henrik. It works like a charm.
 
Also consider looking up the $facts hash instead of directly looking up
individual facts like $clientnoop. This to be future proof. (See the
link you posted regarding details).
In fact, using the $fact hash was my first choice. But I didn't find a clientnoop  fact, nor a noop fact.
Did I miss something ?

Henrik Lindberg

unread,
Sep 22, 2015, 8:10:15 AM9/22/15
to puppet...@googlegroups.com
On 2015-21-09 22:34, Frédéric Lespez wrote:
>
> In the 3.x function API use:
>
> lookupvar('varname')
>
> In the 4.x function API use:
>
> closure_scope.lookupvar('varname')
>
> Here is the specification for the 4.x API.
> https://github.com/puppetlabs/puppet-specifications/blob/master/language/func-api.md
> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fpuppetlabs%2Fpuppet-specifications%2Fblob%2Fmaster%2Flanguage%2Ffunc-api.md&sa=D&sntz=1&usg=AFQjCNE-GaBgyAfECLuUg52Idq1Erm6KtQ>
>
>
> Thank Henrik. It works like a charm.
>
> Also consider looking up the $facts hash instead of directly looking up
> individual facts like $clientnoop. This to be future proof. (See the
> link you posted regarding details).
>
> In fact, using the $fact hash was my first choice. But I didn't find a
> clientnoop fact, nor a noop fact.
> Did I miss something ?
>

The docs are vague regarding $clientnoop - have to dig deeper to find
out what is going on wrt. that variable.

If you expected (as I did, but I did not really try things out) that it
is a fact and should have been in the $facts hash, then I suggest that a
ticket is logged. It is either a problem in code, or something that
should be mentioned in documentation.

- 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/557e90f2-d9e2-4d1b-a9c5-96dcf3f6bfd4%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/557e90f2-d9e2-4d1b-a9c5-96dcf3f6bfd4%40googlegroups..com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages