Hi all I have been pondering this for a while, but not yet seen a clean way to do it I have a few puppet classes (apache/ntp/mysql/bacula/nagios/etc) I would like to generate part of my bacula and nagios configs for each host based on which other classes that host belongs to (or to put it another way, I would like to export variables from classes which would be used by my bacula and nagios classes). As an example, my bacula template for a client currently has: FileSet { Name = "FileSet-<%= hostname %>" Include { Options { signature = MD5 compression = GZIP } <% backup_include.split(/, */).each do |file| -%> File = <%= file %> <% end -%> # INC = <%= backup_include %> } Exclude { File = /sys File = /proc File = /var/tmp <% backup_exclude.split(/, */).each do |file| -%> File = <%file %> <% end -%> } } I would like the backup_include to automatically include /var/www if the host is an apache server (for example), and I would like those directories to be defined in the apache class (not the bacula class) Any clever ways of achieving this? -- 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.
Bernd Adamowicz
2011-Sep-22 13:41 UTC
AW: [Puppet Users] Export variables into other classes
I''m not quite sure, but maybe exported resources could help. Some introductions are found here: * http://docs.puppetlabs.com/guides/exported_resources.html * http://blog.gurski.org/index.php/2010/01/28/automatic-monitoring-with-puppet-and-nagios/ They also cover the Nagios issue. Cheers Bernd> -----Ursprüngliche Nachricht----- > Von: puppet-users@googlegroups.com [mailto:puppet- > users@googlegroups.com] Im Auftrag von Chris > Gesendet: Donnerstag, 22. September 2011 15:06 > An: Puppet Users > Betreff: [Puppet Users] Export variables into other classes > > Hi all > > I have been pondering this for a while, but not yet seen a clean way > to do it > > I have a few puppet classes (apache/ntp/mysql/bacula/nagios/etc) > > I would like to generate part of my bacula and nagios configs for each > host based on which other classes that host belongs to (or to put it > another way, I would like to export variables from classes which would > be used by my bacula and nagios classes). > > As an example, my bacula template for a client currently has: > > FileSet { > Name = "FileSet-<%= hostname %>" > Include { > Options { > signature = MD5 > compression = GZIP > } > <% backup_include.split(/, */).each do |file| -%> File = <%= file > %> > <% end -%> > # INC = <%= backup_include %> > } > Exclude { > File = /sys > File = /proc > File = /var/tmp > <% backup_exclude.split(/, */).each do |file| -%> File = <%> file %> > <% end -%> > } > } > > > I would like the backup_include to automatically include /var/www if > the host is an apache server (for example), and I would like those > directories to be defined in the apache class (not the bacula class) > > Any clever ways of achieving this? > > -- > 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.-- 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.
Chris Picton
2011-Sep-22 16:58 UTC
Re: AW: [Puppet Users] Export variables into other classes
It seems that exported resources only cover resources, not variables, which would be what I may want here In my case, I am not using the builtin puppet nagios types (I am using exported resources to create the host entries), but for each host I need to customise those files based on classes to which the host belongs. Similarly with my bacula class, I need to add additional directories to the generated file based on the classes to which a host belongs, but the bacula client File resource is only realized on the storage node for that particular client. On 2011/09/22 3:41 PM, Bernd Adamowicz wrote:> I''m not quite sure, but maybe exported resources could help. Some introductions are found here: > > * http://docs.puppetlabs.com/guides/exported_resources.html > * http://blog.gurski.org/index.php/2010/01/28/automatic-monitoring-with-puppet-and-nagios/ > > They also cover the Nagios issue. > > Cheers Bernd > >> -----Ursprüngliche Nachricht----- >> Von: puppet-users@googlegroups.com [mailto:puppet- >> users@googlegroups.com] Im Auftrag von Chris >> Gesendet: Donnerstag, 22. September 2011 15:06 >> An: Puppet Users >> Betreff: [Puppet Users] Export variables into other classes >> >> Hi all >> >> I have been pondering this for a while, but not yet seen a clean way >> to do it >> >> I have a few puppet classes (apache/ntp/mysql/bacula/nagios/etc) >> >> I would like to generate part of my bacula and nagios configs for each >> host based on which other classes that host belongs to (or to put it >> another way, I would like to export variables from classes which would >> be used by my bacula and nagios classes). >> >> As an example, my bacula template for a client currently has: >> >> FileSet { >> Name = "FileSet-<%= hostname %>" >> Include { >> Options { >> signature = MD5 >> compression = GZIP >> } >> <% backup_include.split(/, */).each do |file| -%> File =<%= file >> %> >> <% end -%> >> # INC =<%= backup_include %> >> } >> Exclude { >> File = /sys >> File = /proc >> File = /var/tmp >> <% backup_exclude.split(/, */).each do |file| -%> File =<%>> file %> >> <% end -%> >> } >> } >> >> >> I would like the backup_include to automatically include /var/www if >> the host is an apache server (for example), and I would like those >> directories to be defined in the apache class (not the bacula class) >> >> Any clever ways of achieving this? >> >> -- >> 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.-- 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.
Robin Lee Powell
2011-Sep-22 17:52 UTC
Re: [Puppet Users] Export variables into other classes
On Thu, Sep 22, 2011 at 06:05:33AM -0700, Chris wrote:> Hi all > > I have been pondering this for a while, but not yet seen a clean way > to do it > > I have a few puppet classes (apache/ntp/mysql/bacula/nagios/etc) > > I would like to generate part of my bacula and nagios configs for each > host based on which other classes that host belongs to (or to put it > another way, I would like to export variables from classes which would > be used by my bacula and nagios classes). > > As an example, my bacula template for a client currently has: > > FileSet { > Name = "FileSet-<%= hostname %>" > Include { > Options { > signature = MD5 > compression = GZIP > } > <% backup_include.split(/, */).each do |file| -%> File = <%= file > %> > <% end -%> > # INC = <%= backup_include %> > } > Exclude { > File = /sys > File = /proc > File = /var/tmp > <% backup_exclude.split(/, */).each do |file| -%> File = <%> file %> > <% end -%> > } > } > > > I would like the backup_include to automatically include /var/www if > the host is an apache server (for example), and I would like those > directories to be defined in the apache class (not the bacula class) > > Any clever ways of achieving this?Sorry for the useless post, but: I''d love to hear how to do this too! I suspect that http://www.devco.net/archives/2011/06/06/puppet_backend_for_hiera.php (suggested in another thread) could handle it, but is there a native way? -Robin -- http://singinst.org/ : Our last, best hope for a fantastic future. Lojban (http://www.lojban.org/): The language in which "this parrot is dead" is "ti poi spitaki cu morsi", but "this sentence is false" is "na nei". My personal page: http://www.digitalkingdom.org/rlp/ -- 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 Sep 22, 2011, at 6:05 AM, Chris wrote:> Hi all > > I have been pondering this for a while, but not yet seen a clean way > to do it > > I have a few puppet classes (apache/ntp/mysql/bacula/nagios/etc) > > I would like to generate part of my bacula and nagios configs for each > host based on which other classes that host belongs to (or to put it > another way, I would like to export variables from classes which would > be used by my bacula and nagios classes). > > As an example, my bacula template for a client currently has: > > FileSet { > Name = "FileSet-<%= hostname %>" > Include { > Options { > signature = MD5 > compression = GZIP > } > <% backup_include.split(/, */).each do |file| -%> File = <%= file > %> > <% end -%> > # INC = <%= backup_include %> > } > Exclude { > File = /sys > File = /proc > File = /var/tmp > <% backup_exclude.split(/, */).each do |file| -%> File = <%> file %> > <% end -%> > } > } > > > I would like the backup_include to automatically include /var/www if > the host is an apache server (for example), and I would like those > directories to be defined in the apache class (not the bacula class) > > Any clever ways of achieving this?---- I do use in one of my manifests... if (tagged("ldap::server_install")) { $ldap_servers = "ldapi:/// ldap://ldap.domain" } else { ... } so I would think that you could have something like ", ''/var/www''" if (tagged("apache::server")) in your ''backup_include'' string. Craig -- 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 Sep 22, 8:05 am, Chris <iwouldratherbesleeping...@gmail.com> wrote:> Hi all > > I have been pondering this for a while, but not yet seen a clean way > to do it > > I have a few puppet classes (apache/ntp/mysql/bacula/nagios/etc) > > I would like to generate part of my bacula and nagios configs for each > host based on which other classes that host belongs to (or to put it > another way, I would like to export variables from classes which would > be used by my bacula and nagios classes). > > As an example, my bacula template for a client currently has: > > FileSet { > Name = "FileSet-<%= hostname %>" > Include { > Options { > signature = MD5 > compression = GZIP > } > <% backup_include.split(/, */).each do |file| -%> File = <%= file > %> > <% end -%> > # INC = <%= backup_include %> > } > Exclude { > File = /sys > File = /proc > File = /var/tmp > <% backup_exclude.split(/, */).each do |file| -%> File = <%> file %> > <% end -%> > } > > } > > I would like the backup_include to automatically include /var/www if > the host is an apache server (for example), and I would like those > directories to be defined in the apache class (not the bacula class) > > Any clever ways of achieving this?There are no particularly good ways to achieve that if you restrict yourself to Puppet DSL. Generally speaking, you never want your manifests to inquire about the node''s target state -- they should dictate instead. Anyway, all the approaches I know that inquire about what other classes are declared for a given node suffer from order- dependence issues, so at best, using them makes your manifests brittle. Without going too far outside Puppet DSL, you can achieve your goal by externalizing some or all of your data. Then, instead of asking whether a particular class _has been_ assigned to the node, you can use extlookup(), hiera, or similar to ask whether that class _is supposed to be_ assigned, whether it already has been or not. For best results, use the same data to drive the actual choice of whether to assign the class. If you go that far, however, then you''re already most of the way to a data-driven external node classifier. You might find it useful to go the rest of the way, thereby moving the logic out of your manifests altogether. John -- 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 Thu, 2011-09-22 at 13:26 -0700, jcbollinger wrote:> > > > I would like the backup_include to automatically include /var/www if > > the host is an apache server (for example), and I would like those > > directories to be defined in the apache class (not the bacula class) > > > > Any clever ways of achieving this? > > > There are no particularly good ways to achieve that if you restrict > yourself to Puppet DSL. Generally speaking, you never want your > manifests to inquire about the node''s target state -- they should > dictate instead. Anyway, all the approaches I know that inquire about > what other classes are declared for a given node suffer from order- > dependence issues, so at best, using them makes your manifests > brittle. > > Without going too far outside Puppet DSL, you can achieve your goal by > externalizing some or all of your data. Then, instead of asking > whether a particular class _has been_ assigned to the node, you can > use extlookup(), hiera, or similar to ask whether that class _is > supposed to be_ assigned, whether it already has been or not. For > best results, use the same data to drive the actual choice of whether > to assign the class. > > If you go that far, however, then you''re already most of the way to a > data-driven external node classifier. You might find it useful to go > the rest of the way, thereby moving the logic out of your manifests > altogether. >Currently my nodes are stored in ldap I could either specify classes by including the ldap attribute puppetClass directly, or setting a custom variable ($is_bacula_director or $is_nagios_client), and include the class generic_server on all nodes, which would look something like: class generic_server { if $is_bacula_client == 1 { include bacula::client } ... } afaik, extlookup can''t query against ldap, but if I use the $is_* variables, I could add a lot of if (is_apache_server == 1) { <add_backup_dir /var/www> } if (is_dns_server == 1) { <add_backup_dir /var/named> } (pseudo)code to the bacula::client template Is that along the lines of what you meant? I would prefer to keep my classes self-contained, which means I would rather have a generic include mechanism in the bacula template/client class, and specify all needed directories in the relevant dns/apache classes. Any thoughts 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.
On Thu, 2011-09-22 at 13:26 -0700, jcbollinger wrote:> > > > I would like the backup_include to automatically include /var/www if > > the host is an apache server (for example), and I would like those > > directories to be defined in the apache class (not the bacula class) > > > > Any clever ways of achieving this? > > > There are no particularly good ways to achieve that if you restrict > yourself to Puppet DSL. Generally speaking, you never want your > manifests to inquire about the node''s target state -- they should > dictate instead. Anyway, all the approaches I know that inquire about > what other classes are declared for a given node suffer from order- > dependence issues, so at best, using them makes your manifests > brittle. > > Without going too far outside Puppet DSL, you can achieve your goal by > externalizing some or all of your data. Then, instead of asking > whether a particular class _has been_ assigned to the node, you can > use extlookup(), hiera, or similar to ask whether that class _is > supposed to be_ assigned, whether it already has been or not. For > best results, use the same data to drive the actual choice of whether > to assign the class.I currently am using LDAP external nodes, and I see two ways of assigning classes to hosts 1. use the puppetClass attribute, and assign classes directly. However, extlookup cannot query ldap, so I could not query this data within my manifests 2. add all hosts to a global generic_server class. I could then set variables in ldap like is_bacula_client=1, is_apache_server=1, etc. generic_server would look something like: class generic_server { if $is_apache_server == 1 { include apache::server } if $is_bacula::client == 1 { include bacula::client } etc etc } This would allow me to use a construct of the following pseudocode in my bacula client template file if is_apache_server == 1 then print "File = /var/www" end if is_dns_server == 1 then print "File = /var/named end etc etc This would work, but requires that I add conditionals for all other classes in the bacula class I would like to keep the classes self contained, so that the bacula client template file or class has a generic include mechanism, and the apache class would define all the required backup directories. Any ideas around that? Chris -- 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 Sep 23, 6:40 am, Chris <iwouldratherbesleeping...@gmail.com> wrote:> On Thu, 2011-09-22 at 13:26 -0700, jcbollinger wrote: > > > > I would like the backup_include to automatically include /var/www if > > > the host is an apache server (for example), and I would like those > > > directories to be defined in the apache class (not the bacula class) > > > > Any clever ways of achieving this? > > > There are no particularly good ways to achieve that if you restrict > > yourself to Puppet DSL. Generally speaking, you never want your > > manifests to inquire about the node''s target state -- they should > > dictate instead. Anyway, all the approaches I know that inquire about > > what other classes are declared for a given node suffer from order- > > dependence issues, so at best, using them makes your manifests > > brittle. > > > Without going too far outside Puppet DSL, you can achieve your goal by > > externalizing some or all of your data. Then, instead of asking > > whether a particular class _has been_ assigned to the node, you can > > use extlookup(), hiera, or similar to ask whether that class _is > > supposed to be_ assigned, whether it already has been or not. For > > best results, use the same data to drive the actual choice of whether > > to assign the class. > > I currently am using LDAP external nodes, and I see two ways of > assigning classes to hosts > > 1. use the puppetClass attribute, and assign classes directly. However, > extlookup cannot query ldap, so I could not query this data within my > manifestsextlookup() does not query LDAP *out-of-the-box*, but you can hook up alternative back-ends to it. I think an LDAP back-end is available (though not in the base distribution), but even if not then it shouldn''t be that hard to create one. By the same token, it shouldn''t be unreasonably difficult to write your own custom function that performs LDAP variable lookups for you. [...]> I would like to keep the classes self contained, so that the bacula > client template file or class has a generic include mechanism, and the > apache class would define all the required backup directories. Any > ideas around that?Forgive me, but I''m missing the distinction you are trying to draw. Why is it more self-contained for all your service classes to expose variables intended only for consumption by your bacula client template than it is for your bacula template or class to contain code for every potential service? In the latter case everything would at least be centralized, and you would not need to place additional requirements on every single other service class. Nevertheless, if you insist on proceeding in the direction you describe, then you may find it convenient to use the ''scope'' object exposed to your template to examine all in-scope variables. For each service the node has, declare a top-level variable having a recognizable name pattern and whatever value you want. Your template should easily be able to sift these out of the overall set of in-scope variables and do whatever you want with them. John -- 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.