Using Virtual Resources and create_resource combination

257 views
Skip to first unread message

CD

unread,
Jan 15, 2014, 10:57:41 PM1/15/14
to puppet...@googlegroups.com
Hi friends,

I have an issue where that I receive error Error 400 on SERVER: Cannot reassign variable name on node app1. When I run the agent on admin1 it works fine, but when I run the agent on app1 it give me the error.

Having read few forum posts it seems this is most likely that the same resource is used. resource network::if::static is used with eth0 in the same class when it runs for admin1 and app1. I believe when it run on admin1 variables are used without any problem and when it run on app1 it find the variable has been used for admin1. It appears these kind of issues are addressed by creating virtual resources. However I cannot figure out how I can define virtual resources and combine that with create_resources. I need to use the create_resources because I was to pass the hieradata to the resource.

Any ideas how I can address this problem?

Details of the implementation given below:

I have following hieradata which applied to each server:

/etc/puppet/hieradata/admin1.json
{
   "networks":{
      "eth0":{
         "ipaddress":"192.168.1.1",
         "netmask":"255.255.255.0"
      }
   }
}

/etc/puppet/hieradata/app1.json
{
   "networks":{
      "eth0":{
         "ipaddress":"192.168.1.2",
         "netmask":"255.255.255.0"
      }
   }
}

I have a class call foundation and it has following files
/etc/puppet/modules/foundation/manifests/init.pp
class foundation {
    include foundation::network
}

/etc/puppet/modules/foundation/manifests/network.pp
class foundation::network{

    # Defaults for network configuration
    $nic_default = {
        'ensure' => 'up'
    }

    # Extract Data from Hiera for the host in concern
    $nics   = hiera("networks",{})

    # Configure networks based on the parameters
    create_resources(network::if::static, $nics, $nic_default)

}

Above class is included in base node and individual nodes has extended from the base node
/etc/puppet/manifests/nodes.pp
node base {
   include foundation
}

node admin1 inherits base {
}

node app1 inherits base {
}

Thanks,
CD

CD

unread,
Jan 16, 2014, 2:00:38 AM1/16/14
to puppet...@googlegroups.com
ok I found a workaround to my problem. I updated the network module (https://forge.puppetlabs.com/razorsedge/network) so that it is now accepting a label as the name rather than interface (eth0 etc). In this way I can provide a unique name and get away with assigning same name leading to error. then I introduced a new parameter to module to accept interface. For example my data now updated as follows.

/etc/puppet/hieradata/admin1.json
{
   "networks":{
      "admin1-admin":{
         "interface":"eth0",
         "ipaddress":"192.168.1.1",
         "netmask":"255.255.255.0"
      }
   }
}

But I still like to know is it possible to use the create_resources and virtual resources together where I need to pass hieradata also.

Thanks,
CD

Jose Luis Ledesma

unread,
Jan 16, 2014, 3:32:16 AM1/16/14
to puppet...@googlegroups.com
I'm not sure, but I remember reading something like:
create_resources(@user, $myusers)

Although I don't really know if this is the best solution for you

jcbollinger

unread,
Jan 16, 2014, 10:58:51 AM1/16/14
to puppet...@googlegroups.com


On Wednesday, January 15, 2014 9:57:41 PM UTC-6, CD wrote:
Hi friends,

I have an issue where that I receive error Error 400 on SERVER: Cannot reassign variable name on node app1. When I run the agent on admin1 it works fine, but when I run the agent on app1 it give me the error.

Having read few forum posts it seems this is most likely that the same resource is used. resource network::if::static is used with eth0 in the same class when it runs for admin1 and app1. I believe when it run on admin1 variables are used without any problem and when it run on app1 it find the variable has been used for admin1.


No.  Puppet is complaining about a variable, not a resource.  That is, something of the general form

$some_var = 'a value'

Each variable may be assigned a value at most once.  There are two likely scenarios for how this might be happening:
  1. Most likely, you have a reassignment of the affected variable inside a conditional statement, such that it is processed for node app1 but not for node admin1.
  2. Alternatively, you may have a global variable assignment at top scope in a manifest file that is not loaded for node admin1, but is loaded for node app1.  Such an assignment in principle applies to all nodes (and therefore is wrong for all nodes), but it won't be seen when node app1's catalog is compiled (which makes such statement placement a very bad idea in general, error notwithstanding).
Example of (1):

class site {
  $is_app_node = false

  if $hostname =~ /^app/ {
    # WRONG:
    $is_app_node = true
  }
}


Example of (2):
manifests/site.pp:
-----------
# Top-scope declaration ok here:
$is_app_node = false

node app1 {
  include myapp
}

modules/myapp/manifests/init.pp:
-----------
# Top-scope declaration unwise here:
$is_app_node = true

class myapp {
  # ...
}




I don't see any issue with the code and data you presented.  Have you checked the master's logs for more information?  I'm thinking it ought to tell you the name of the affected variable.  If it doesn't already do so, then perhaps turning on --debug output will induce it to do so.


John

CD

unread,
Jan 22, 2014, 9:19:15 PM1/22/14
to puppet...@googlegroups.com
Hi John,

Thanks a lot for the information. I checked the variables and could not find anything defined twice.

In my workaround I updated the module code slightly and managed to fix the issue I face.

This is the original code

I changed the code by introducing parameter called interface. In the interface and I pass the value "eth0" etc and in title I pass a unique value.  

define network::if::static (
  $interface,
  $ensure,
  $ipaddress,
  $netmask,
  $gateway = '',
  $macaddress = '',
  $userctl = false,
  $mtu = '',
  $ethtool_opts = '',
  $peerdns = false,
  $dns1 = '',
  $dns2 = '',
  $domain = '',
)
..
..
  network_if_base { $interface:
    ensure       => $ensure,
    ipaddress    => $ipaddress,
    netmask      => $netmask,
    gateway      => $gateway,
    macaddress   => $macaddy,
    bootproto    => 'none',
    userctl      => $userctl,
    mtu          => $mtu,
    ethtool_opts => $ethtool_opts,
    peerdns      => $peerdns,
    dns1         => $dns1,
    dns2         => $dns2,
    domain       => $domain,
  }

Though I haven't dive deep in module code it seems having title variable repeated with value "eth0" when it runs for each server seems. 

Thanks,
Chaminda 

jcbollinger

unread,
Jan 23, 2014, 9:23:43 AM1/23/14
to puppet...@googlegroups.com


On Wednesday, January 22, 2014 8:19:15 PM UTC-6, CD wrote:
Hi John,

Thanks a lot for the information. I checked the variables and could not find anything defined twice.

In my workaround I updated the module code slightly and managed to fix the issue I face.



I'm glad you've resolved the issue.

 
Though I haven't dive deep in module code it seems having title variable repeated with value "eth0" when it runs for each server seems. 



Each node's catalog is compiled independently of every other node's, except for with respect to collecting exported resources.  Moreover, it is extremely common for different nodes to each declare resources having the same type and title.  I am confident, therefore, that that was not in itself your problem.  I cannot explain what the problem really was, though.


John

CD

unread,
Feb 3, 2014, 4:24:44 PM2/3/14
to puppet...@googlegroups.com
Thanks for the information John.
Reply all
Reply to author
Forward
0 new messages