I use defined every so often so I would be sad if it was removed, it's handy for certain things of things:
common/foreman_proxy/manifests/params.pp: if defined(Class['puppet::server::ca']) { common/foreman_proxy/manifests/params.pp: } elsif defined(Class['puppet::server']) { common/foreman_proxy/manifests/params.pp: if defined(Class['foreman_proxy::role::build']) { common/mysql/manifests/rights.pp: if ! defined(Mysql_user ["${user}@${host}"]) { An example: if ! defined(Mysql_user ["${user}@${host}"]) { mysql_user { "${user}@${host}": password_hash => mysql_password($password), require => File["/root/.my.cnf"], } } In my foreman_proxy stuff: # puppetca settings if defined(Class['puppet::server::ca']) { $puppetca = true $autosign_location = "/etc/puppet/autosign.conf" $puppetca_cmd = "/usr/sbin/puppetca" $puppet_group = "puppet" # puppetrun settings $puppetrun = true $puppetrun_cmd = "/usr/sbin/puppetrun" } elsif defined(Class['puppet::server']) { # puppetrun settings $puppetca = false $puppetrun = true $puppetrun_cmd = "/usr/sbin/puppetrun" } else { $puppetca = false $puppetrun = false } I'm sure there are other ways to do it but this seems elegant and makes sense at times. I could set variables in those other classes and then check for them I suppose but what is the harm in doing things this way? I don't see why defined() couldn't be implemented properly rather than being removed. On Thu, Jan 19, 2012 at 3:17 PM, Nick Fagerlund < nick.fagerl...@puppetlabs.com> wrote: > > > On Jan 19, 11:01 am, "R.I.Pienaar" <r...@devco.net> wrote: > > ----- Original Message ----- > > > Defined() doesn't suck! It's a 100% reliable way to check what > > > classes and defined types are available to the autoloader. I challenge > anyone > > > to find me an example of this usage that fails. > > > > can you give an example of this use case pls? > > Well... that's something I realized after I posted that, is I'm not > sure if anyone WANTS a reliable way to test the autoloader. (Obviously > people do want a way to check for resource instances, which is why > defined() keeps getting used for that...) > > But anyway! Say you make a module for a network service and you want > it to be able to manage its own firewall rule. You know of a defined > type for firewall rules, and you're using it, but you want your module > to be portable and you know of good reasons why someone wouldn't be > using your iptables module. > > So, you can conditionally declare the rule if the defined type is > available to the autoloader, and otherwise you don't attempt to manage > the firewall and expect that the user has read the documentation and > will make a hole for the service themselves. > > if defined(firewall::iptables::rule) { > firewall::iptables::rule {'mysql_server': > ...etc. etc. > } > } > > See? It's just a way to peek around at what the user has installed. > > Which... maybe implies that it should be renamed to "installed()." > Dunno. > > -- > 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+unsubscr...@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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.