Hi gang, Is it possible to test if a particular resource has already been defined? I''d like to do something like this: if !Host["$fqdn"] { host {"$fqdn": ip => "$ipaddress_eth0" } } Essentially, test to see if there is no Host resource defined for the current server and if not, add a host entry for itself using the IP address of eth0. Possible? Ta, Avi --~--~---------~--~----~------------~-------~--~----~ 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-Jun-18 08:03 UTC
[Puppet Users] Re: Testing if a resource is already defined
Hi> Is it possible to test if a particular resource has already been > defined? I''d like to do something like this: > > if !Host["$fqdn"] { > host {"$fqdn": ip => "$ipaddress_eth0" } > } > > Essentially, test to see if there is no Host resource defined for the > current server and if not, add a host entry for itself using the IP > address of eth0.http://reductivelabs.com/trac/puppet/wiki/FunctionReference#defined 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 -~----------~----~----~----~------~----~------~--~---
Udo Waechter
2009-Jun-19 21:33 UTC
[Puppet Users] Re: Testing if a resource is already defined
Hello, On 18.06.2009, at 10:03, Peter Meier wrote:> > Hi > >> Is it possible to test if a particular resource has already been >> defined? I''d like to do something like this: >> >> if !Host["$fqdn"] { >> host {"$fqdn": ip => "$ipaddress_eth0" } >> } >> >> Essentially, test to see if there is no Host resource defined for the >> current server and if not, add a host entry for itself using the IP >> address of eth0. > > http://reductivelabs.com/trac/puppet/wiki/FunctionReference#definedIn principle, this should do. Unfortunately there''s this small catch that: "This function is unfortunately dependent on the parse order of the configuration when testing whether a resource is defined." I have many situations where i would like to test whether a class ist defined or not. This does not work for most situations. Would it be possible to rewrite "defined" such that it is not dependent on the parse order of manifest? As I understand puppet, this is not easily achievable. I am not sure, though. All the best, udo. -- :: udo waechter - root@zoide.net :: N 52º16''30.5" E 8º3''10.1" :: genuine input for your ears: http://auriculabovinari.de :: your eyes: http://ezag.zoide.net :: your brain: http://zoide.net
Eric Gerlach
2009-Jun-19 21:53 UTC
[Puppet Users] Re: Testing if a resource is already defined
On Thu, Jun 18, 2009 at 12:14:59PM +1000, Avi Miller wrote:> > Hi gang, > > Is it possible to test if a particular resource has already been > defined? I''d like to do something like this: > > if !Host["$fqdn"] { > host {"$fqdn": ip => "$ipaddress_eth0" } > } > > Essentially, test to see if there is no Host resource defined for the > current server and if not, add a host entry for itself using the IP > address of eth0. > > Possible?It sounds like you might be trying to define a host in more than one place. I''m just a journeryman myself, but I think according to The Puppet Way (TM) that''s a Bad Thing (TM). If you make sure that the host is only potentially defined in one place, you don''t have to worry about this. Cheers, -- Eric Gerlach, Network Administrator Federation of Students University of Waterloo p: (519) 888-4567 x36329 e: egerlach@feds.uwaterloo.ca --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Avi Miller
2009-Jun-19 21:55 UTC
[Puppet Users] Re: Testing if a resource is already defined
Eric Gerlach wrote:> It sounds like you might be trying to define a host in more than one place. > I''m just a journeryman myself, but I think according to The Puppet Way (TM) > that''s a Bad Thing (TM).Yes, I am and yes, it is, but I don''t have (much) choice without making our manifests rather larger and more cumbersome. Using the defined() function and replacing the host{} type with a custom add_host{} definition (that wraps the function) works just fine. cYa, Avi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Scott Smith
2009-Jun-19 22:01 UTC
[Puppet Users] Re: Testing if a resource is already defined
Avi Miller wrote:> Eric Gerlach wrote: >> It sounds like you might be trying to define a host in more than one place. >> I''m just a journeryman myself, but I think according to The Puppet Way (TM) >> that''s a Bad Thing (TM). > > Yes, I am and yes, it is, but I don''t have (much) choice without making > our manifests rather larger and more cumbersome. Using the defined() > function and replacing the host{} type with a custom add_host{} > definition (that wraps the function) works just fine. >Why don''t you just define it virtually and realize it at will? -scott -- scott@ohlol.net http://github.com/ohlol --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Avi Miller
2009-Jun-19 22:28 UTC
[Puppet Users] Re: Testing if a resource is already defined
On 20/06/2009, at 8:01 AM, Scott Smith <scott@ohlol.net> wrote:> Why don''t you just define it virtually and realize it at will?Because the value for the IP address changes depending on where it appears in the manifest. I''m working in an environment where each server has at least 2 and up to 6 addresses, and I have to programmatically determine which one to use in /etc/hosts. It''s not pretty, but it''s working well for us. Thanks, Avi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Schmitt
2009-Jun-23 11:21 UTC
[Puppet Users] Re: Testing if a resource is already defined
Udo Waechter wrote:> Would it be possible to rewrite "defined" such that it is not dependent > on the parse order of manifest? > > As I understand puppet, this is not easily achievable. I am not sure, > though.Making defined() (and other parse-order dependent stuff) parse-order independent would require a complete rework of the way puppet evaluates manifests, so that it can solve complex logical problems, like what should happen when two parts of a configuration depend on each other? Without proof, I believe that a general solution for that would be NP-hard (because it might be a SAT instance, http://en.wikipedia.org/wiki/Boolean_satisfiability_problem). Regards, DavidS --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---