Ask Your Question
0

Clarification wanted on facts and global variables in Puppet v4

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

cm01 gravatar image

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

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

See https://ask.puppet.com/question/27122...

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
Chris

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 => 10.200.0.0
network_lo => 127.0.0.0

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

2. V4 Server

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

networking => {
          network => "10.200.0.0"
          network => "fe80::"
      network => "10.200.0.0",
      network6 => "fe80::"
          network => "127.0.0.0"
          network => "::1"
      network => "127.0.0.0",
      network6 => "::1"
  network => "10.200.0.0",
  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": "10.200.0.0",
    "network6": "fe80::",
    "network6_eth0": "fe80::",
    "network6_lo": "::1",
    "network_eth0": "10.200.0.0",
    "network_lo": "127.0.0.0",

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

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

https://docs.puppet.com/facter/3.1/core_facts.html#network

"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!

https://docs.puppet.com/facter/3.3/release_notes.html
Facter 3.2 ...
(more)
edit retag flag offensive close merge delete

Comments

This appears to be a bug report, not a question. You should submit it at https://tickets.puppetlabs.com/

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

4 Answers

Sort by » oldest newest most voted
1

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

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
1

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

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
0

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

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. https://docs.puppet.com/puppet/latest...

edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit
0

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

Emerson Prado gravatar image

Yes, 'network' is a fact:
https://docs.puppet.com/facter/3.1/co...
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

Stats

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

Seen: 140 times

Last updated: Nov 01 '16