ascodemus
2010-Feb-23 09:19 UTC
[Puppet Users] How to conditionally include classes based on environment?
Hi, I''m new to puppet (doing an assesment of the puppet features currently) and I believe many of you can tell me how to resolve these questions I''m unable to find answers for. I have the "Pulling Strings with Puppet"-book and have been crawling through the reductivelabs puppet wiki-pages without answers. Q1) How can I include a class for a node depending on the status of the managed node? Example is it possible to do include a class based on existence of a file e.g. “/root/puppet/dl580” on the managed puppet- client node like: node webserv2 inherits basenode { <condition_if_file_dl580_exists> { include dl580 } <condition_if_file_dl380_exists> { include dl380 } ...etc... } Q2) Is it possible to pass information (e.g. string) i.e. an output of an “exec” execution on a puppet-client and store this information into a puppet variable? Fiddling around with facts set as environment variables “FACTER_name=value” would somehow do this, but this is a bit of a hack? A good use for this would be to do an exec execution on a managed puppet node (puppet client) and based on the information passed, different paths could be taken. e.g. $return_string = exec { ... } case $return_string { was_blue: { <do_something_specific_to_blue_hosts> } was_red: { <do_something_specific_to_red_hosts> } was_yellow: { <do_something_specific_to_yellow_hosts> } default: { <do_something_that’s_colorblind> } } Q3) Well when I’m hacking with the FACTER-variables, I notice that if I’ve included new FACTER-variables within the /etc/init.d/puppet (or sourced from there from another file) this obviously requires puppet restart to make my own FACTERs available – is there any other method to make my own FACTERs available once set without need to restart the puppet client? Below is an example that could be useful: case $virt_or_physical { physical: { <do_something_specific_to_physical_hosts> } virtual: { <do_something_specific_to_virtual_hosts> } default: { <do_something_else> } } Thanks in advance! B.R. Asko -- 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.
Tim Stoop
2010-Feb-24 11:36 UTC
[Puppet Users] Re: How to conditionally include classes based on environment?
Hi there, On 23 feb, 10:19, ascodemus <ascode...@gmail.com> wrote:> Q1) How can I include a class for a node depending on the status of > the managed node? Example is it possible to do include a class based > on existence of a file e.g. “/root/puppet/dl580” on the managed puppet- > client node like:<snip> Nope, that''s not possible, since the manifests are compiled on the puppetmaster and it therefore has no access to the filesystem of your client at that time. The usual solution for this is to create a fact for this. There are some examples here: http://reductivelabs.com/trac/puppet/wiki/AddingFacts> Q2) Is it possible to pass information (e.g. string) i.e. an output of > an “exec” execution on a puppet-client and store this information into > a puppet variable?Take a look at the generate function: http://docs.reductivelabs.com/references/0.25.1rc2/function.html#generate I think that can do what you need.> Q3) Well when I’m hacking with the FACTER-variables, I notice that if > I’ve included new FACTER-variables within the /etc/init.d/puppet (or > sourced from there from another file) this obviously requires puppet > restart to make my own FACTERs available – is there any other method > to make my own FACTERs available once set without need to restart the > puppet client?I don''t think adding facter variables to /etc/init.d/puppet is common practice, really. I''d prefer to create an actual fact. This can usually be done by very simple snippets of code, as seen on the page I pointed to as answer to your Q1. Hope this helps! -- Kind regards, Tim -- 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.
ascodemus
2010-Feb-25 16:01 UTC
[Puppet Users] Re: How to conditionally include classes based on environment?
Hi Tim and thanks for the replies. The code snippet for the facter will probably turn out to be very welcome. Regarding the generate function:> > Q2) Is it possible to pass information (e.g. string) i.e. an output of > > an “exec” execution on a puppet-client and store this information into > > a puppet variable? > > > Take a look at the generate function: > http://docs.reductivelabs.com/references/0.25.1rc2/function.html#gene... > > I think that can do what you need.I thought also before that this could do the trick, but as indicated on the web (http://docs.reductivelabs.com/references/stable/ function.html#generate) the generate executes a command on the puppet MASTER-server (not on the client), so this does not work as such - unless the command to run on the puppet master server is actually a remote SSH command to the respective puppet client. We''ll perhaps I''m thinking too much in procedural way as writing a shell or a shell script. Probably once I get to know the tool more in practice I realize I can live without the above. Thanks again, -Asko -- 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
2010-Feb-26 17:37 UTC
[Puppet Users] Re: How to conditionally include classes based on environment?
On Feb 25, 10:01 am, ascodemus <ascode...@gmail.com> wrote:> I thought also before that this could do the trick, but as indicated > on the web (http://docs.reductivelabs.com/references/stable/ > function.html#generate) the generate executes a command on the puppet > MASTER-server (not on the client), so this does not work as such -Indeed. All the information the Puppetmaster has about any client comes ultimately from the facts that client presents to it and the manifests you write. Even if you use storeconfigs to retain and share client information, that information is still originally derived from those same sources. If you want the Puppetmaster to know about the result of running a command on the client, then you need to write a custom fact. Tim already referred you to some docs on that. -- 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.