On Thursday, March 14, 2013 2:28:13 AM UTC-5, [email protected] wrote: > > Am Mittwoch, 13. März 2013 17:00:18 UTC+1 schrieb jcbollinger: > >> >> >> My problem now is that I don't know how to implement "ensure" for this >>> case, as I cannot use "ensurable" in the type. >>> >> >> Your problem is that you are conflating distinct (for your purposes) >> aspects of your resource's state. If you care at times whether the >> variable is declared at all or not, and at other times what its value is, >> then those should be separate properties. Your resource declarations will >> then look like this: >> >> env_var { 'AWESOMENESS': >> value => 'meh', >> # optional: >> ensure => present >> } >> >> or >> >> env_var { 'AWESOMENESS': >> ensure => absent >> } >> > > I've changed the logic of exists? a bit to reflect this, and it works. > However, one has to remember not to provide a value if "ensure => absent" > was specified. >
That's under your control. Were I you, I would probably implement flushing for this resource type instead of applying changes directly in response to property changes. See http://docs.puppetlabs.com/guides/provider_development.html#flushing. That way your provider can act based on all of its properties together, instead of acting separately on each one. Alternatively, your provider's value=() method could condition its behavior on its resource's should(:ensure) value (and perhaps vise versa, too), so that it does not perform needless operations. > Or is there a way to check this in the provider? > There are validation and munging hooks for resource parameters, but they only work on a parameter-by-parameter basis. As far as I know, there is no whole-resource validation hook built into the framework. 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
