Hi, So, I am writing a module to install and configure ucarp. There is only one module in puppet forge and that is not that good. In ucarp, same configuration files have to be served on two servers and to configure the host I am defining a custom resource ucarp::host::config. So, for using, I''ll have to create this resource two times on two different servers. So, this resource generates few files out of which few will be common and hence starts generating multiple definitions error. So, to use the module on Host A, a guy will have to first include ucarp (to do basic stuff like package installation and making sure service is running) and then something like ucarp::host::config { "ucarp-test": node_id => ''1'', password => "testpass", interface_primary => ''eth0'', interface_vip => ''eth1'', vip_addr => ''1.1.1.1'', vip_addr_netmask => ''2.2.2.2'', } On Host B, everything would be same except the vip_addr value which results in multiple definition errors for the files that I''m serving. What is it that can be done? -- Cheers, Abhijeet R http://blog.abhijeetr.com -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Wednesday, October 24, 2012 10:07:56 AM UTC-5, Abhijeet Rastogi wrote:> > Hi, > > So, I am writing a module to install and configure ucarp. There is only > one module in puppet forge and that is not that good. > In ucarp, same configuration files have to be served on two servers and > to configure the host I am defining a custom resource > ucarp::host::config. So, for using, I''ll have to create this resource > two times on two different servers. So, this resource generates few > files out of which few will be common and hence starts generating > multiple definitions error. > > So, to use the module on Host A, a guy will have to first include ucarp > (to do basic stuff like package installation and making sure service is > running) and then something like > > ucarp::host::config { "ucarp-test": > node_id => ''1'', > password => "testpass", > interface_primary => ''eth0'', > interface_vip => ''eth1'', > vip_addr => ''1.1.1.1'', > vip_addr_netmask => ''2.2.2.2'', > } > > On Host B, everything would be same except the vip_addr value which > results in multiple definition errors for the files that I''m serving. > What is it that can be done? > >Resources need to be unique only within the scope of one node. Two different nodes'' resources cannot cause a multiple definition error. Either I don''t understand what you are trying to do, or what you''re actually doing is not what you intend to do. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/W1fO1ZpxiUcJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Abhijeet R
2012-Oct-25 09:39 UTC
Re: [Puppet Users] Re: Multiple resource definition error
In ucarp, multiple instances can be run and I have to run two instances of ucarp. So, what ever I do, either create a custom resource ot parameterised classes, they will have to be declared twice. The code can be seen here https://github.com/shadyabhi/puppet-ucarp I have developed two versions, one with classes and the other with resources. And both suffer the same issue. I would really appreciate if anyone can help me with this. On Thu 25 Oct 2012 02:32:22 AM IST, jcbollinger wrote:> > > On Wednesday, October 24, 2012 10:07:56 AM UTC-5, Abhijeet Rastogi wrote: > > Hi, > > So, I am writing a module to install and configure ucarp. There is > only > one module in puppet forge and that is not that good. > In ucarp, same configuration files have to be served on two > servers and > to configure the host I am defining a custom resource > ucarp::host::config. So, for using, I''ll have to create this resource > two times on two different servers. So, this resource generates few > files out of which few will be common and hence starts generating > multiple definitions error. > > So, to use the module on Host A, a guy will have to first include > ucarp > (to do basic stuff like package installation and making sure > service is > running) and then something like > > ucarp::host::config { "ucarp-test": > node_id => ''1'', > password => "testpass", > interface_primary => ''eth0'', > interface_vip => ''eth1'', > vip_addr => ''1.1.1.1'', > vip_addr_netmask => ''2.2.2.2'', > } > > On Host B, everything would be same except the vip_addr value which > results in multiple definition errors for the files that I''m serving. > What is it that can be done? > > > Resources need to be unique only within the scope of one node. Two > different nodes'' resources cannot cause a multiple definition error. > Either I don''t understand what you are trying to do, or what you''re > actually doing is not what you intend to do. > > > John > > -- > You received this message because you are subscribed to the Google > Groups "Puppet Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/puppet-users/-/W1fO1ZpxiUcJ. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en.-- Cheers, Abhijeet R http://blog.abhijeetr.com -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Oct-25 13:23 UTC
Re: [Puppet Users] Re: Multiple resource definition error
On Thursday, October 25, 2012 4:38:31 AM UTC-5, Abhijeet Rastogi wrote:> > In ucarp, multiple instances can be run and I have to run two instances > of ucarp. So, what ever I do, either create a custom resource ot > parameterised classes, they will have to be declared twice. >You''re still confusing me. Your initial message led me to believe that your two ucarp instances are supposed to run on different hosts. Did I misunderstand? If the ucarp instances are on different hosts, then it seems to me that each of those hosts'' catalogs should declare only the ucarp instance for that host. You should not need multiple ucarp declarations for that setup. Even if you wrote two separate declarations in your manifest, you would want to use a conditional statement to ensure that no more than one was actually applied to any host. Under those circumstances, Puppet would not complain about duplicate resources.> > The code can be seen here https://github.com/shadyabhi/puppet-ucarp > > I have developed two versions, one with classes and the other with > resources. And both suffer the same issue. >If you really do intend to declare two different ucarp instances on the *same node*, then giving the resources different titles -- such as "ucarp-test1" and "ucarp-test2" -- should get you around the duplicate resource issue. (Note: defined-type instances are resources, but classes are not.) John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/0ZiMgeg52wgJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Abhijeet R
2012-Oct-25 14:07 UTC
Re: [Puppet Users] Re: Multiple resource definition error
On Thu 25 Oct 2012 06:53:24 PM IST, jcbollinger wrote:> > You''re still confusing me. Your initial message led me to believe > that your two ucarp instances are supposed to run on different hosts. > Did I misunderstand?In total, there will be four ucarp instances. Two running on two different machines. The issue here is that, the file resources defined inside the user-defined ucarp::host::config resource is throwing the error. I am not sure how do I solve that. Meanwhile, I had a look at https://github.com/bodepd/puppet-ensure_resource and this kind of solved my problem. I was able to do what I intended by wrapping the file resources defined inside the ucarp::host::config inside ensure_resource. Everything worked perfectly on 2.7.9 as expected. I was testing everything by having only one module and doing everything in site.pp. But, when I moved to the actual environment which includes 2.6.13, it isn''t able to find the resource type ucarp::host::config and complains about invalid resource type. Any idea why that could be happening? The situation is something like: 1. There is init.pp in module ucarp containing class ucarp. (As it should). It has a include "*" written in the first line. 2. There is host.pp in modules/ucarp/manifests which has class ucarp::host. In that there is a "define config )(args....)". 3. Then in manifests/production/myproject/templates.pp, there are many classes defined that for each type of host. 4. There is manifests/production/myproject/nodes.pp which has nodes defined. In that, there is a node A which inherits some class from the templates.pp. 5. In this node, I did something like: include ucarp ucarp::host::config { "ucarp-test": .. .. } The puppet complains saying that err: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type ucarp::host ::config at /etc/puppet/manifests/production/myproject/nodes.pp:614 on node A I am not sure how to proceed? I have also tried adding "include ucarp::host" in the node definition but no success.> > If the ucarp instances are on different hosts, then it seems to me > that each of those hosts'' catalogs should declare only the ucarp > instance for that host. You should not need multiple ucarp > declarations for that setup. Even if you wrote two separate > declarations in your manifest, you would want to use a conditional > statement to ensure that no more than one was actually applied to any > host. Under those circumstances, Puppet would not complain about > duplicate resources. > > > The code can be seen here > https://github.com/shadyabhi/puppet-ucarp > <https://github.com/shadyabhi/puppet-ucarp> > > I have developed two versions, one with classes and the other with > resources. And both suffer the same issue. > > > > If you really do intend to declare two different ucarp instances on > the /same node/, then giving the resources different titles -- such as > "ucarp-test1" and "ucarp-test2" -- should get you around the duplicate > resource issue. (Note: defined-type instances are resources, but > classes are not.) > > > John > > -- > You received this message because you are subscribed to the Google > Groups "Puppet Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/puppet-users/-/0ZiMgeg52wgJ. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en.-- Cheers, Abhijeet R http://blog.abhijeetr.com -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Oct-25 15:09 UTC
Re: [Puppet Users] Re: Multiple resource definition error
On Thursday, October 25, 2012 9:06:30 AM UTC-5, Abhijeet Rastogi wrote:> > On Thu 25 Oct 2012 06:53:24 PM IST, jcbollinger wrote: > > > > You''re still confusing me. Your initial message led me to believe > > that your two ucarp instances are supposed to run on different hosts. > > Did I misunderstand? > > In total, there will be four ucarp instances. Two running on two > different machines. The issue here is that, the file resources defined > inside the user-defined ucarp::host::config resource is throwing the > error. I am not sure how do I solve that. > > Meanwhile, I had a look at > https://github.com/bodepd/puppet-ensure_resource and this kind of > solved my problem.Any problem solved by that function would be better solved by avoiding duplicate declarations in the first place. At best it''s a band-aid, not a fix, but it is completely wrong if you cannot be certain that all declarations of the target resource are identical. If they are all identical, then the correct solution is to lift the declaration(s) out of its duplicative context (often a defined type) into a class that the defined type declares, or can rely on having been declared. If they are * not* all identical, then you have a *bug* in your manifests, and function just masks it. Your problem appears to be a special case of the latter. You have this definition (excerpted, and name edited): define ucarp::host::config( $node_id, $password="", $interface_primary, $interface_vip, $vip_addr, $vip_addr_netmask, $vip_addr_gw, $ensure=present ) { # ... file { "vip-up": ensure => $present, path => ''/etc/sysconfig/carp/vip-up'', content => template("ucarp/vip-up.erb"), require => Package[''ucarp''], } # other related scripts ... } Now, the template interpolates some of the definition''s parameters, making the output specific to one ucarp instance. Therefore, declaring it indirectly via ensure_resource() is incorrect: you end up with only the script for *one* of your ucarp instances, where what you actually need is a separate script for each one. That''s what Puppet has been trying to tell you all along. You need to add some kind of instance identifier to the name of the file you are creating (and to the resource title if you continue to separate it), such as file { "/etc/sysconfig/carp/vip${vip_id}-up": ensure => $present, content => template("ucarp/vip-up.erb"), require => Package[''ucarp''], } (Where you would need to set $vip_id appropriately via an additional parameter to your definition, or some other means.) If, contrary to appearances, you really do want only one vip_up script (and similar) for all instances, then its declaration does not belong in a per-instance definition. It looks like you could pull it up to class ucarp::host. I was able to do what I intended by wrapping the> file resources defined inside the ucarp::host::config inside > ensure_resource. Everything worked perfectly on 2.7.9 as expected. I > was testing everything by having only one module and doing everything > in site.pp. But, when I moved to the actual environment which includes > 2.6.13, it isn''t able to find the resource type ucarp::host::config and > complains about invalid resource type. Any idea why that could be > happening? >Yes. If you are trying to declare an instance of nested definition ucarp::host::config before or without including class ucarp::host, then it is possible that the autoloader will not find it. You should move it to its own file in the module (modules/ucarp/manifests/host/config.pp, based on its name).> > The situation is something like: > > 1. There is init.pp in module ucarp containing class ucarp. (As it > should).Sort of. If your module "ucarp" has a main class (i.e. one with the same name as the module), then init.pp is where it should appear. It is not necessary to have such a class, however.> It has a include "*" written in the first line. >I''m surprised that works at all, and your results suggest that it doesn''t do what you think. It would be much better to explicitly ''include'' the classes you want. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/4Yx1heS5gegJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.