Ask Your Question
0

hiera_hash Cannot reassign variable '$network' in site.pp

asked 2016-07-10 23:24:36 -0500

cm01 gravatar image

updated 2016-10-19 23:49:17 -0500

site.pp

$mysql = hiera_hash(mysql)
$network = hiera_hash(network)
$nfs = hiera_hash(nfs)

default.json

   "mysql" : {},
   "network" : {},
   "nfs" : {},

This gives

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

Removing 'network' entry from default.json gives

Could not find data item network in any Hiera data file and no default supplied at /etc/puppetlabs/code/environments/prod/manifests/site.pp

Can anybody explain what's going on ?

Chris
Hiera v3.2, Puppet master 4 (2.4)

Well I did search for it, but all I got was

grep -r network manifests/
manifests/site.pp:$network = hiera_hash(network)

(none)

and

grep -r \$network modules/  
modules/network/manifests/classes/tagging/configuration.pp: if $network['vlan'] {
modules/network/manifests/classes/tagging/configuration.pp:     tagged_vlan { $network['vlan']: }

which leads to

define tagged_vlan() {

    file { "/etc/sysconfig/network-scripts/ifcfg-bond0.${name}":
        ensure  => file,
        content => template('network/etc/sysconfig/network-scripts/ifcfg-bond0.erb')
    }

    file { "/etc/sysconfig/network-scripts/ifcfg-bridge0.${name}":
        ensure  => file,
        content => template('network/etc/sysconfig/network-scripts/ifcfg-bridge0.erb')
    }

    ifcfg-eth-vlan{ "eth0.${name}":
        vlan => $name,
        interface  => "eth0",
    }

    ifcfg-eth-vlan{ "eth1.${name}":
        vlan => $name,
        interface  => "eth1",
    }

}

UPDATED: 2016-10-20

Hi Guys, so I still need an answer to this.
It works on a a client node, but not on the puppetmaster, but its the puppetmaster module ... sigh

puppet agent -t --noop --debug --verbose

last few lines
Debug: Facter: resolving load_average facts.
Debug: Facter: fact "load_averages" has resolved to {
  15m => 0.01,
  1m => 0,
  5m => 0.01
}.
Debug: Facter: resolving Xen facts.
Debug: Failed to load library 'msgpack' for feature 'msgpack'
Debug: Puppet::Network::Format[msgpack]: feature msgpack is missing
Debug: catalog supports formats: pson yaml dot binary
Debug: Using cached connection for https://puppetmaster103.ops.sac.int.threatmetrix.com:8140
Debug: Caching connection for https://puppetmaster103.ops.sac.int.threatmetrix.com:8140
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Cannot reassign variable '$network' at /etc/puppetlabs/code/environments/prod/manifests/site.pp:25:10 on node puppetmaster103.ops.sac.int.threatmetrix.com
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

and searching for 'network'

grep network prun_network_err.txt 
Debug: Facter: resolving networking facts.
Debug: Facter: fact "network_eth0" has resolved to "10.200.0.0".
Debug: Facter: fact "network" has resolved to "10.200.0.0".
Debug: Facter: fact "network6_eth0" has resolved to "fe80::".
Debug: Facter: fact "network6" has resolved to "fe80::".
Debug: Facter: fact "network_lo" has resolved to "127.0.0.0".
Debug: Facter: fact "network6_lo" has resolved to "::1".
Debug: Facter: fact "networking" has resolved to {
          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::",
Debug: Facter: resolving networking facts.
Debug: Facter: fact "network_eth0" has resolved to "10.200.0.0".
Debug: Facter: fact "network" has resolved to "10.200.0.0".
Debug: Facter: fact "network6_eth0" has resolved to "fe80::".
Debug: Facter: fact "network6" has resolved to "fe80::".
Debug: Facter: fact ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-10-20 15:03:54 -0500

smarlow gravatar image

I suspect that the issue stems from the fact that Puppet exposes $::network as a fact, which causes it to think that you're trying to redefine it with the lookup. A simple workaround would be to change the name of your variable to something that doesn't conflict with this but is still informative.

edit flag offensive delete link more

Comments

1

Confirmed: [root@agent /]# cat test.pp $network = "oops" [root@agent /]# puppet apply test.pp Error: Evaluation Error: Cannot reassign variable '$network' at /test.pp:1:10 on node agent.localdomain See puppet apply -e 'notify{$network:}' for reason

geoff_williams gravatar imagegeoff_williams ( 2016-12-10 03:36:51 -0500 )edit
0

answered 2016-07-11 02:21:49 -0500

updated 2016-07-11 02:22:18 -0500

That message Cannot reassign variable means that you have declared the same variable $network in two places in your manifests, which isn't allowed in Puppet. Note it has nothing to do with the network key being used in more than one place in Hiera, which is allowed (and often necessary). You should be able to find the duplication by using grep -r \$network manifests/.

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-07-10 23:24:36 -0500

Seen: 428 times

Last updated: Oct 19 '16