mark
2009-Nov-25 15:10 UTC
[Puppet Users] how do i override/redefine a resource that is declared in another class?
hi all, newbie here... i''ve been fiddling around with the inherits form...but..i can''t seem to get any headway out of it. i''ve been googling and looking at some docs, but i think i might still be confused as to how things work. - what i''ve found seems to talk about overrinding variables $variable, but..i''m trying to change a resource/service is this completely different? - the docs i see refer to class names as simple words like "class snoopy", but everywhere i see classes here are of the form snoopy::lucy... anyway from what i can find from the error message, it doesn''t like that in my manifest file (node mynode { ... }) has a stanza: service { netfs: stuff=>data stuff=>data ... } it says netfs is already defined. so i looked around and it appears that my manifest file has an include: example "include base::services" the file it''s loading also has an include that calls another file, and THAT file has some classes in it..one of which has a netfs stanza like above. i want to override that in my manifest/node file. however i can''t change anything anywhere except in my manifest/node file. one solution i know will work is to replace my first include with the actual file itself, and replace the 2nd include with the huge class file and change the class manually. but expanding everything doesn''t seem like it would be the suave way to go in any complex setup. it''d be nice to be able to say: do this, except for this. my fear was that maybe the ''except for'' method might be frowned upon too as too ''goto'' like and kludgy in nature? hopefully the solution is simple and i''m just not getting the syntax right.. any advice would be appreciated! thanks much, mark -- 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.
Peter Meier
2009-Nov-25 20:17 UTC
Re: [Puppet Users] how do i override/redefine a resource that is declared in another class?
Hi> i''ve been fiddling around with the inherits form...but..i can''t seem > to get any headway out of it.What is your problem with inheritance? Maybe we can give you a way out and following example shows you that it is the way to go: $ cat foo.pp class a { file{''/tmp/a'': ensure => file} file{''/tmp/b'': ensure => file} } class b inherits a { File[''/tmp/b'']{ensure => absent } } include a include b $ puppet foo.pp notice: //a/File[/tmp/a]/ensure: created $ you can include the inherited class anywhere you''d like to. So for example simply write disable classes for the services you don''t want to manage on certain nodes and then include these in your node. cheers pete -- 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.
mark
2009-Nov-26 14:48 UTC
[Puppet Users] Re: how do i override/redefine a resource that is declared in another class?
back on my own account again, updating: hi! thanks for the advice i think i don''t understand the nature of ''include''. in my mind include is something that is invisible to the actual engine that does things..it''s a shorthand that replaces ''include X'' with the contents of X and then the software goes to work on the final result and humans don''t have to look at hugely long files. so when i see a file that says class A { blah } include A it seems like it''s redundant...so i''m thinking in the puppet world..does include have some stronger meaning like "and execute the code"? here is the specifics of my multilayer include world: ------------------------------------------------------ my attempt to trace the lineage of the resource i''m bumping into in my manifest/node file: node "chquoteq02.tradearca.com" { ... include base::setup ... i''d like to TURN ON SERVICE netfs for this node } ------------------------------------------------------ in /etc/puppet/modules-base/trunk/base/manifests/init.pp: class base::setup { ... include services::setup ... } ------------------------------------------------------ in /etc/puppet/modules-base/trunk/services/manifests/init.pp: class services::setup { ... include services::base ... } class services::base { ... service { netfs: ... TURNS OFF SERVICE } ... } so give this, i tried this (but it didn''t work) in my manifest/node file: class myoverrideclass inherits services::base { service { netfs: enable => true, ensure => running, hasstatus => true, } } include base::setup include myoverrideclass i ran: puppetd -ov --no-daemonize on the client server and got: err: Could not retrieve catalog: Puppet::Parser::AST::Resource failed with error ArgumentError: Duplicate definition: Service[netfs] is already defined in file /etc/puppet/modules-base/trunk/services/ manifests/init.pp at line 385; cannot redefine at /etc/puppet/ manifests/nodes/chquoteq02.tradearca.com.node:491 on node chquoteq02.tradearca.com i even tried moving the ''include base::setup'' to be above the ''myoverrideclass'' definition but still the same problem... On Nov 25, 2:17 pm, Peter Meier <peter.me...@immerda.ch> wrote:> Hi > > > i''ve been fiddling around with the inherits form...but..i can''t seem > > to get any headway out of it. > > What is your problem with inheritance? Maybe we can give you a way out > and following example shows you that it is the way to go: > > $ cat foo.pp > class a { > file{''/tmp/a'': ensure => file} > file{''/tmp/b'': ensure => file} > > } > > class b inherits a { > File[''/tmp/b'']{ensure => absent } > > } > > include a > include b > $ puppet foo.pp > notice: //a/File[/tmp/a]/ensure: created > $ > > you can include the inherited class anywhere you''d like to. So for > example simply write disable classes for the services you don''t want > to manage on certain nodes and then include these in your node. > > cheers pete-- 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.
Silviu Paragina
2009-Nov-27 23:16 UTC
Re: [Puppet Users] Re: how do i override/redefine a resource that is declared in another class?
On 26.11.2009 16:48, mark wrote:> back on my own account again, updating: > hi! thanks for the advice > i think i don''t understand the nature of ''include''. in my mind include > is something that is invisible to the actual engine that does > things..it''s a shorthand > > that replaces ''include X'' with the contents of X and then the software > goes to work on the final result and humans don''t have to look at > hugely long files. >no, not by far. Include has the meaning, make sure that the rules in the specified class are also applied. Multiple includes of the same class from different places will apply the class only once. Require (>=0.25, hope this is what is called never actually used it :"> ) is similar, with the sole exception that it makes sure that the definitions in the specified class are applied before the definitions in your class. Also note that there is no particular order in which your definitions are applied. When you use before it just means that the current resource will be applied before the other resource, but 1000 other resources could be applied in between.(same goes for require)> so when i see a file that says > > class A { > > blah > > } > > include A > > > > it seems like it''s redundant...so i''m thinking in the puppet > world..does include have some stronger meaning like "and execute the > code"? > >You should think at it more of a description, not code. (like you would in any other descriptive language)> > here is the specifics of my multilayer include world: > > ------------------------------------------------------ > > my attempt to trace the lineage of the resource i''m bumping into > > in my manifest/node file: > > node "chquoteq02.tradearca.com" { > > ... > > include base::setup > > ... > > i''d like to TURN ON SERVICE netfs for this node > > > > } > > ------------------------------------------------------ > > in /etc/puppet/modules-base/trunk/base/manifests/init.pp: > > > > class base::setup { > > ... > > include services::setup > > ... > > } > > ------------------------------------------------------ > > in /etc/puppet/modules-base/trunk/services/manifests/init.pp: > > > > class services::setup { > > ... > > include services::base > > ... > > } > > > > class services::base { > > ... > > service { netfs: > > ... TURNS OFF SERVICE > > } > > ... > > } > > > > > > > > so give this, i tried this (but it didn''t work) in my manifest/node > file: > > class myoverrideclass inherits services::base { > > service { netfs: > > enable => true, > > ensure => running, > > hasstatus => true, > > } > > } >Service with "S" not "s". When the first letter is uppercase the statement alters an already existing definition, when it''s lower case it''s a new definition. Here: http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#classes .> > > include base::setup > > include myoverrideclass > > > > i ran: puppetd -ov --no-daemonize >I prefer puppetd --test (faster to write and not too verbose)> on the client server and got: > > err: Could not retrieve catalog: Puppet::Parser::AST::Resource failed > with error ArgumentError: Duplicate definition: Service[netfs] is > already defined in file /etc/puppet/modules-base/trunk/services/ > manifests/init.pp at line 385; cannot redefine at /etc/puppet/ > manifests/nodes/chquoteq02.tradearca.com.node:491 on node > chquoteq02.tradearca.com > > > > i even tried moving the ''include base::setup'' to be above the > ''myoverrideclass'' definition but still the same problem... > > On Nov 25, 2:17 pm, Peter Meier<peter.me...@immerda.ch> wrote: > >> Hi >> >> >>> i''ve been fiddling around with the inherits form...but..i can''t seem >>> to get any headway out of it. >>> >> What is your problem with inheritance? Maybe we can give you a way out >> and following example shows you that it is the way to go: >> >> $ cat foo.pp >> class a { >> file{''/tmp/a'': ensure => file} >> file{''/tmp/b'': ensure => file} >> >> } >> >> class b inherits a { >> File[''/tmp/b'']{ensure => absent } >> >> } >> >> include a >> include b >> $ puppet foo.pp >> notice: //a/File[/tmp/a]/ensure: created >> $ >> >> you can include the inherited class anywhere you''d like to. So for >> example simply write disable classes for the services you don''t want >> to manage on certain nodes and then include these in your node. >> >> cheers pete >> > -- > > 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. > > >Good luck and welcome to puppet, Silviu -- 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.
mark inaba
2009-Dec-02 05:23 UTC
Re: [Puppet Users] Re: how do i override/redefine a resource that is declared in another class?
thanks so much to peter meier and silviu paragina for their assistance. i didn''t realize i needed the capital S in Service and the slightly different format in changing the value of the service resource than when first creating it. i wanted to test it to make sure it worked, and it did! thanks so much again :) -mark On Fri, Nov 27, 2009 at 5:16 PM, Silviu Paragina <silviu@paragina.ro> wrote:> > On 26.11.2009 16:48, mark wrote: >> >> back on my own account again, updating: >> hi! thanks for the advice >> i think i don''t understand the nature of ''include''. in my mind include >> is something that is invisible to the actual engine that does >> things..it''s a shorthand >> >> that replaces ''include X'' with the contents of X and then the software >> goes to work on the final result and humans don''t have to look at >> hugely long files. >> > > no, not by far. > Include has the meaning, make sure that the rules in the specified class are > also applied. Multiple includes of the same class from different places will > apply the class only once. > Require (>=0.25, hope this is what is called never actually used it :"> ) is > similar, with the sole exception that it makes sure that the definitions in > the specified class are applied before the definitions in your class. > Also note that there is no particular order in which your definitions are > applied. When you use before it just means that the current resource will be > applied before the other resource, but 1000 other resources could be applied > in between.(same goes for require) > > >> so when i see a file that says >> >> class A { >> >> blah >> >> } >> >> include A >> >> >> >> it seems like it''s redundant...so i''m thinking in the puppet >> world..does include have some stronger meaning like "and execute the >> code"? >> >> > > You should think at it more of a description, not code. (like you would in > any other descriptive language) > >> >> here is the specifics of my multilayer include world: >> >> ------------------------------------------------------ >> >> my attempt to trace the lineage of the resource i''m bumping into >> >> in my manifest/node file: >> >> node "chquoteq02.tradearca.com" { >> >> ... >> >> include base::setup >> >> ... >> >> i''d like to TURN ON SERVICE netfs for this node >> >> >> >> } >> >> ------------------------------------------------------ >> >> in /etc/puppet/modules-base/trunk/base/manifests/init.pp: >> >> >> >> class base::setup { >> >> ... >> >> include services::setup >> >> ... >> >> } >> >> ------------------------------------------------------ >> >> in /etc/puppet/modules-base/trunk/services/manifests/init.pp: >> >> >> >> class services::setup { >> >> ... >> >> include services::base >> >> ... >> >> } >> >> >> >> class services::base { >> >> ... >> >> service { netfs: >> >> ... TURNS OFF SERVICE >> >> } >> >> ... >> >> } >> >> >> >> >> >> >> >> so give this, i tried this (but it didn''t work) in my manifest/node >> file: >> >> class myoverrideclass inherits services::base { >> >> service { netfs: >> >> enable => true, >> >> ensure => running, >> >> hasstatus => true, >> >> } >> >> } >> > > Service with "S" not "s". When the first letter is uppercase the statement > alters an already existing definition, when it''s lower case it''s a new > definition. Here: > http://reductivelabs.com/trac/puppet/wiki/LanguageTutorial#classes . > > >> >> >> include base::setup >> >> include myoverrideclass >> >> >> >> i ran: puppetd -ov --no-daemonize >> > > I prefer puppetd --test (faster to write and not too verbose) >> >> on the client server and got: >> >> err: Could not retrieve catalog: Puppet::Parser::AST::Resource failed >> with error ArgumentError: Duplicate definition: Service[netfs] is >> already defined in file /etc/puppet/modules-base/trunk/services/ >> manifests/init.pp at line 385; cannot redefine at /etc/puppet/ >> manifests/nodes/chquoteq02.tradearca.com.node:491 on node >> chquoteq02.tradearca.com >> >> >> >> i even tried moving the ''include base::setup'' to be above the >> ''myoverrideclass'' definition but still the same problem... >> >> On Nov 25, 2:17 pm, Peter Meier<peter.me...@immerda.ch> wrote: >> >>> >>> Hi >>> >>> >>>> >>>> i''ve been fiddling around with the inherits form...but..i can''t seem >>>> to get any headway out of it. >>>> >>> >>> What is your problem with inheritance? Maybe we can give you a way out >>> and following example shows you that it is the way to go: >>> >>> $ cat foo.pp >>> class a { >>> file{''/tmp/a'': ensure => file} >>> file{''/tmp/b'': ensure => file} >>> >>> } >>> >>> class b inherits a { >>> File[''/tmp/b'']{ensure => absent } >>> >>> } >>> >>> include a >>> include b >>> $ puppet foo.pp >>> notice: //a/File[/tmp/a]/ensure: created >>> $ >>> >>> you can include the inherited class anywhere you''d like to. So for >>> example simply write disable classes for the services you don''t want to >>> manage on certain nodes and then include these in your node. >>> >>> cheers pete >>> >> >> -- >> >> 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. >> >> >> > > Good luck and welcome to puppet, > Silviu >-- 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.