On Wed, 13 Mar 2013 09:00:18 -0700 (PDT)
jcbollinger <[email protected]> wrote:
> 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
> }
>
>
> John
>
I tend to disagree here. If the presence of an environment variable
inherently means that it has a value and the absence of a value
inherently means that the resource is absent I don't see the point in
having two properties.
I'd suggest to not use ensurable and define the ensure property
yourself:
in your type:
newproperty(:ensure) do
newvalues :absent
newvalues /.*/ # or whatever is valid for a value
end
in your provider, drop exists?, create and destroy and use
def ensure
if value = get_environment_variable(resource[:name])
value
else
:absent
end
end
def ensure=(new_value)
if new_value == :absent
destroy_environment_variable(resource[:name])
else
set_environment_variable(resource[:name], new_value)
end
end
you can then either specify
env_var { 'TMP':
ensure => 'C:\TEMP'
}
or
env_var { 'TMP':
ensure => absent,
}
-Stefan
--
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.