phundisk
2013-Apr-26 17:36 UTC
[Puppet Users] Create a file which lists all server names with a given environment variable
I am presuming that this is something I need to do with stored configs, but there might also be another way to do it. I am looking to create a file called /root/production.servers which will list all my production servers. All production servers have the puppet variable of $environment=''production'' in the nodes.pp. Is there a way I can utilize this variable to create this file? Is stored configs the best option here? -- _____________________________________________________ This email and any files transmitted with it are confidential and intended solely for the addressee. If you received this email in error, please do not disclose the contents to anyone; kindly notify the sender by return email and delete this email and any attachments from your system. © 2011 Currensee Inc. is a member of the National Futures Association (NFA) Member ID 0403251 | Over the counter retail foreign currency (Forex) trading may involve significant risk of loss. It is not suitable for all investors and you should make sure you understand the risks involved before trading and seek independent advice if necessary. Performance, strategies and charts shown are not necessarily predictive of any particular result and past performance is no indication of future results. Investor returns may vary from Trade Leader returns based on slippage, fees, broker spreads, volatility or other market conditions. Currensee Inc | 54 Canal St 4th Floor | Boston, MA 02114 | +1.617.624.3824 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Apr-29 13:53 UTC
[Puppet Users] Re: Create a file which lists all server names with a given environment variable
On Friday, April 26, 2013 12:36:21 PM UTC-5, phundisk wrote:> > I am presuming that this is something I need to do with stored configs, > but there might also be another way to do it. > > I am looking to create a file called /root/production.servers which will > list all my production servers. All production servers have the puppet > variable of $environment=''production'' in the nodes.pp. Is there a way I > can utilize this variable to create this file? Is stored configs the best > option here? >There are basically two approaches: 1. The master knows at all times which nodes are supposed to be production servers. This would involve an exhaustive list of the production servers in a Puppet manifest or in a data file read by the master. In this case, you would probably just build the file via a template and apply it as a normal File resource. No stored configs are needed for this. 2. What I think you''re saying, though, is that you want Puppet to dynamically recognize nodes based on their self-declared environment (if the master were choosing the environment rather than the agent, then you would have case 1). The most natural way to handle this situation is via exported resources (which requires stored configs). For case 2, the key thing to remember is that each production server must declare and export a distinct resource that describes its own node-specific data. That''s not the whole file, but rather just a piece of one. The Concat add-in module is perfect for this sort of thing. You might use it like so: # This class must be included on production servers # (and not on other nodes). class prod::server { # Export a line of the production server list @@concat::fragment { "prodserver-${hostname}": target => ''/root/production.servers'', content => "${hostname}\n" } } # Nodes that should have the server list declare this class; # they may be production servers, but do not need to be. class prod::serverlist { # The target file concat { ''/root/production.servers'': owner => ''root'', group => ''root'', mode => ''0644'' } # Import all the fragments: Concat::Fragment<<| target == ''/root/production.servers'' |>> } The final piece, then, is to ensure that class ''prod::server'' gets declared on all the production servers, and only those. If you''re going to use the $environment variable to control this, then that means putting a conditional statement such as this one somewhere that that is evaluated for every node: if $environment == ''production'' { include ''prod::server'' } That could go in a shared base node or in a common class that all nodes declare. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.