Ask Your Question

Clarification wanted on facts and global variables in Puppet v4

asked 2016-10-26 21:49:09 -0500

cm01 gravatar image

updated 2016-10-31 16:37:40 -0500

I run Puppet server 4.5 aka puppetserver version: 2.4.0.
On this server I have a line in site.pp

$network = hiera_hash(network)

This causes a error (when running the server against itself)

Cannot reassign variable '$network' at /etc/puppetlabs/code/environments/prod/manifests/site.pp

Previous attempts to solve this have led to answers such as:
1. it is a duplicate :
Me: I've searched the code and it isn't
2. puppet exposes $::network as a fact, which causes it to think that you're trying to redefine it with the lookup. :
Me: I have searched google and the puppet docs, but I can't see anywhere where this is stated


Renaming my var makes the error go away (on THIS server), BUT I don't know why.
If I use this server against a 3.3.1 client node, I don't see the error on the client node agent run.

In the other qn, I have shown that 'network' isn't a top level fact (networkING is).

Can anyone definitively show me a ref to (2), or another soln?

Thank you

So, having done a lot of digging, I have discovered some very important info, so bear with me

p> This qn is part of upgrading current systems from 3.2.2, which don't have an issue with the variable declaration/assignment above.

1. V3 Client or Server

facter -v => 2.0.1
facter -p|grep network

network_eth0 =>
network_lo =>

As you can see, 'network' is not a variable/fact.

2. V4 Server

facter -v => 3.2.0
facter -p |grep network

networking => {
          network => ""
          network => "fe80::"
      network => "",
      network6 => "fe80::"
          network => ""
          network => "::1"
      network => "",
      network6 => "::1"
  network => "",
  network6 => "fe80::",

NB: facter -h says:

  -p [ --puppet ]                (Deprecated: use `puppet facts` instead)

All 'network' facts are inside the networkING hash, ie not 'global'
I then tried the 'puppet facts' as per above warning

puppet facts |grep network

    "network": "",
    "network6": "fe80::",
    "network6_eth0": "fe80::",
    "network6_lo": "::1",
    "network_eth0": "",
    "network_lo": "",

    "networking": {
              "network": ""
              "network": "fe80::"
          "network": "",
          "network6": "fe80::"
              "network": ""
              "network": "::1"
          "network": "",
          "network6": "::1"
      "network": "",
      "network6": "fe80::",

Now(!) we see a global level 'network' fact... and searching the docs I found

"This legacy fact is hidden by default in Facter’s command-line output."

WTF - why would you do that... ????

It's no wonder I couldn't see it - it wasn't there to be seen...

The above was exacerbated by the fact (sic) that facter 3.2.0 doesn't actually exist!
Facter 3.2 ...
edit retag flag offensive close merge delete


This appears to be a bug report, not a question. You should submit it at

jorhett gravatar imagejorhett ( 2016-11-02 03:26:31 -0500 )edit

4 answers

Sort by » oldest newest most voted

answered 2016-10-27 13:01:22 -0500

lavaman gravatar image

You showed in your other question that network is actually a fact and since facts are exposed as top-scope variables, you have a reasignment problem.

edit flag offensive delete link more

answered 2016-10-27 03:56:47 -0500

deric gravatar image

First of all it's a bad idea to use global variables. Generate a module puppet module generate my and then you can safely use variable $::my::network (unless you'll install my module).

Puppet 4 does automatic lookup of variables and also facts. Just have a look at facts at your server:

facter -y  network

when you run following Puppet code, you should see the same address

puppet apply -e 'notice($network)'

Reserved variable names are mentioned in documentation. You can probably turn it off, but I wouldn't recommend that, as many modules relies on facts.

edit flag offensive delete link more

answered 2016-10-31 13:36:17 -0500

jorhett gravatar image

Are you attempting to lookup the results of a network() function? You probably want to quote the string you are trying to lookup.

$network = lookup('network', Hash, 'hash')

And you really want to use lookup() instead of hiera_hash, which is obsolete and less powerful.

edit flag offensive delete link more


No, its definitely a hiera hash lookup. This is upgrading a 3.2 system that goes back to even earlier versions ...

cm01 gravatar imagecm01 ( 2016-10-31 16:25:16 -0500 )edit

Well then you just need to quote the value if you are getting it from hiera... $mymodule::network = hiera_hash('network')

jorhett gravatar imagejorhett ( 2016-10-31 17:29:20 -0500 )edit

answered 2016-11-01 05:22:49 -0500

Emerson Prado gravatar image

Yes, 'network' is a fact:
You do have to rename your variable.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-10-26 21:49:09 -0500

Seen: 90 times

Last updated: Nov 01 '16