Ask Your Question

Strange behavior between property and param for an Array value

asked 2015-02-27 23:28:42 -0500

sheshi gravatar image

updated 2015-02-28 14:00:18 -0500

doc75 gravatar image

Hi All,

I am writing a new custom type that has two attributes. One attribute is a param and the other a property and both of them take Array value of key=value pair elements.

newparam(:db_properties, :array_matching => :all) do
  validate do |values|
    values = [values] unless values.is_a? Array
    Puppet.debug("DB properties: #{values.inspect}") **# printing all the key=value elements**

newproperty(:profile_properties, :array_matching => :all) do
  validate do |values|
    values = [values] unless values.is_a? Array
    Puppet.debug("Profile properties: #{values.inspect}") **# printhing only the first key=value elemen**

In the validation method for the param, my debug statement prints all the key=value elements, where as in the validation method for the property, the debug statement is printing only the first key=value element

My understanding is that I should be able to access all elements for both param as well as property if I set the :array_matching to all. What is it that I am doing wrong? How do I access the full Array elements in the validation method of the property.

Any help is greatly appreciated.



edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-03-01 01:23:38 -0500

cpitman gravatar image

updated 2015-03-01 12:01:13 -0500

First of all, Passing :array_matching to a param does nothing, it is not a valid option. This should not be surprising, since a parameter is not compared with a current value on the node, so there is no concept of matching in the first place.

Second, for a property validation is applied to each value in the Array, not on the entire Array at once.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-02-27 23:28:42 -0500

Seen: 230 times

Last updated: Mar 01 '15