Hi.
I seem to have the following problem. This is a code from my custom type:
newproperty(:kernel_options) do
desc "Kernel options for installation boot."
defaultto {}
def insync?(is)
# @should is an Array. see lib/puppet/type.rb insync?
should = @should.first
# if members of hashes are not the same, something
# was added or removed from manifest, so return false
return false unless is.class == Hash and should.class == Hash and
is.keys.sort == should.keys.sort
# check if values of hash keys are equal
is.each do |l,w|
return false unless w == should[l]
end
true
end
def should_to_s(newvalue)
newvalue.inspect
end
def is_to_s(currentvalue)
currentvalue.inspect
end
end
But, if I change the system manually, and if kernel_options property is
not set in my resource, then puppet doesn''t change the system back to
it''s original values.
So, defaultto seems to be ignored. If I set kernel_options => {}
they are indeed obeyed and applied.
Any ideas why is this the case? defaultto works ok if I don''t use the
hash in my property, so I guess it''s something to do with the
is_to_s/should_to_s/insync overrides?
--
Jakov Sosic
www.srce.unizg.hr
--
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-Feb-25 14:55 UTC
[Puppet Users] Re: defaultto in hash property not obeyed
It looks like you are stumbling over a Ruby syntax ambiguity. The fragment
"{}" can be either an empty hash or an empty block. Because the
''defaultto'' method can accept a block, Ruby resolves the
ambiguity in favor
of that interpretation. I think it will work better (and also be clearer)
if you instead write
defaultto Hash.new
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.
Jakov Sosic
2013-Mar-04 17:52 UTC
Re: [Puppet Users] Re: defaultto in hash property not obeyed
On 02/25/2013 03:55 PM, jcbollinger wrote:> > It looks like you are stumbling over a Ruby syntax ambiguity. The > fragment "{}" can be either an empty hash or an empty block. Because > the ''defaultto'' method can accept a block, Ruby resolves the ambiguity > in favor of that interpretation. I think it will work better (and also > be clearer) if you instead write > > defaultto Hash.newThank you, that did it! Really an ambiguity... :) -- 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.