custom type with array property?

301 views
Skip to first unread message

Jakov Sosic

unread,
Oct 21, 2012, 1:04:12 PM10/21/12
to puppet...@googlegroups.com
Hi.


I'm having trouble to write a custom type that accepts array as
property. This is example of my custom type resource definition:

customtype { 'blah':
myarray => ['a','b'],
}


This is what I've got in provider:

def myarray=(value)
require 'pp'
pp value
end


But pp prints only "a"... It would be really helpful if I could see
example of array in custom type... So any help is appreciated.






--
Jakov Sosic
www.srce.unizg.hr

Nan Liu

unread,
Oct 21, 2012, 4:43:11 PM10/21/12
to puppet...@googlegroups.com
Puppet::Type.newtype(:customtype) do
newproperty(:myarray, array_matching => :all) do
end
end

HTH,

Nan

Jakov Sosic

unread,
Oct 22, 2012, 4:53:44 PM10/22/12
to puppet...@googlegroups.com
On 10/21/2012 10:43 PM, Nan Liu wrote:

> Puppet::Type.newtype(:customtype) do
> newproperty(:myarray, array_matching => :all) do
> end
> end

Thank you!

Although you have syntax error, it should be:

newproperty(:myarray, :array_matching => :all) do

Note the collon in front of array_matching.


Also, what I did notice is that this code:

newproperty(:nameservers, :array_matching => :all) do
desc "list of nameservers"
defaultto []
end

Doesn't revert to default if I remove the 'nameservers' property from my
manifest.

I had to overload insync? for it to work, and now type looks like this:

newproperty(:nameservers, :array_matching => :all) do
desc "list of nameservers added to profile"
defaultto []
def insync?(is)
# if members of arrays are not the same, something
# was added or removed from manifest, so return false
return false unless is == should
true
end
end


Although I don't get it because I didn't do anything special in the
overloaded insync? :) And without it won't work. It won't work even if I
set:

nameservers => []

in my manifest.

But never mind, I got it working so I'm satisfied so far.

Stefan Schulte

unread,
Oct 22, 2012, 7:47:14 PM10/22/12
to puppet...@googlegroups.com
Yeah I also consider this a bug. There is a ticket for the issue though
http://projects.puppetlabs.com/issues/10237

-Stefan

Jakov Sosic

unread,
Oct 23, 2012, 8:08:50 AM10/23/12
to puppet...@googlegroups.com
On 10/23/2012 01:47 AM, Stefan Schulte wrote:

> Yeah I also consider this a bug. There is a ticket for the issue though
> http://projects.puppetlabs.com/issues/10237

Yeah that's it! I've added a link as a comment to my type.rb's

Thank you Stefan!
Reply all
Reply to author
Forward
0 new messages