Martin Rio
2013-Apr-13 16:44 UTC
[Puppet Users] Conditional based on whether package is part of the manifest
1. class myssl { 2.* ... code that puts certificate files in place ....* 3. 4.* if package https is installed {* 5. class {''apache::mod::ssl'': } <- enables Apache''s mod_ssl 6. } 7. } In the module above, I''m setting up SSL certificates on a server, and I''d like to to enable Apache''s mod_ssl *only if* the manifest requires the Apache package elsewhere. This is optional because some manifests may use another web server. Is there a way to express a conditional in line 4 that will test whether the httpd package is part of the manifest? Thanks and in advance, and sorry for the newbie questions! -- 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.
Felix Frank
2013-Apr-14 19:02 UTC
Re: [Puppet Users] Conditional based on whether package is part of the manifest
Hi, it''s a good question, with no clear answer. There is the defined() function. Under some circumstances, it can be used to do what you have in mind. Don''t try this though! The problem with this kind of conditional is that imposes parse order dependency. The order can shift as your manifest (including modules) evolves. The clean approach is to define, in a central location, for each node wether ssl support is managed. Ask us about hiera ;-) HTH, Felix On 04/13/2013 06:44 PM, Martin Rio wrote:> 1. class myssl { > 2./ ... code that puts certificate files in place ..../ > 3. > 4./ if package https is installed {/ > 5. class {''apache::mod::ssl'': } <- enables Apache''s mod_ssl > 6. } > 7. } > > In the module above, I''m setting up SSL certificates on a server, and > I''d like to to enable Apache''s mod_ssl *only if* the manifest requires > the Apache package elsewhere. This is optional because some manifests > may use another web server. Is there a way to express a conditional in > line 4 that will test whether the httpd package is part of the manifest? > > Thanks and in advance, and sorry for the newbie questions!-- 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-15 13:40 UTC
[Puppet Users] Re: Conditional based on whether package is part of the manifest
On Saturday, April 13, 2013 11:44:12 AM UTC-5, Martin Rio wrote:> > 1. class myssl { > 2.* ... code that puts certificate files in place ....* > 3. > 4.* if package https is installed {* > 5. class {''apache::mod::ssl'': } <- enables Apache''s mod_ssl > 6. } > 7. } > > In the module above, I''m setting up SSL certificates on a server, and I''d > like to to enable Apache''s mod_ssl *only if* the manifest requires the > Apache package elsewhere. This is optional because some manifests may use > another web server. Is there a way to express a conditional in line 4 that > will test whether the httpd package is part of the manifest? > > Thanks and in advance, and sorry for the newbie questions! >You can address this problem with the help of Hiera, as Felix suggested, but there''s an even easier way: you can simply declare it. class apache::mod::ssl { include ''myssl'' # ... } Adding the "include" statement to class apache::mod::ssl causes class "myssl" to be declared on all nodes that have class "apache::mod::ssl" declared. 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.
jcbollinger
2013-Apr-15 14:00 UTC
[Puppet Users] Re: Conditional based on whether package is part of the manifest
On Monday, April 15, 2013 8:40:05 AM UTC-5, jcbollinger wrote:> > > Adding the "include" statement to class apache::mod::ssl causes class > "myssl" to be declared on all nodes that have class "apache::mod::ssl" > declared. > >That does assume, however, that you don''t need a joint condition. That is, you can make a simple declaration work -- though perhaps a different declaration or a in different place -- as long as you don''t in fact need to jointly evaluate whether myssl is configured AND whether apache is configured. If all of your nodes can be assumed to require one of them, or if one can be assumed needed when the other (or a component of it, such as modssl) is configured, or if certain other special circumstances apply, then plain declarations work. And that SHOULD be the case. If it''s not, then your manifests need a refactoring to make it so. I''d be happy to discuss that further if you wish. 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.