Hello everyone ! I'm trying to create custom type...
# puppet
r
Hello everyone ! I'm trying to create custom types along a provider in my Puppet setup, I was wondering if anyone of you had a proper documentation for doing so ? I find the official documentation quite useless and not really good. I tried to copy the behavior of what's done for the
puppetlabs::mysql
modules, but I end up with errors.
Well I should try to do a better Google search before asking out 😛 This looks like what I need https://dev.to/betadots/the-ruby-side-of-puppet-part-3-custom-types-and-providers-4hma
t
let me know if there are issues or errors in the article.
r
Oh! Thanks so much for the article, it's demystifying a lot of stuff already. I'm trying to read it all and try to understand everything.. I might ask you a few questions if I'm still missing some things if it's not a bother. I'll definitely let you know if I find an issue or anything 🙂
Would you recommend to use the new resource_api, or the old v1 API ? Just to know better what someone who's already work with both opinion is I suppose newer is better, but I see that a lot of puppet modules (from voxpupuli for example) still use the old way
I followed the document for the
resource_api
but I end with an error `undefined method `find`` .. I'll try with the V1 API 😄
t
Personally I prefer the old api. But others have different opinions.
r
And it works!! I'm able to create a resource querying an HTTP API, and deleting it!! Thank you SO MUCH for the article, it really covers everything 🥳
t
thank you for the feedback.
r
It's so nice, I've been working with Puppet for more than 4 years and now I think that possibilities are endless !
y
I was using resource_api last few times and it was good for me
r
Hey! Just a small question.. I'm having trouble with one of my two types.. One of my type does not require me to add the
ensure => present
field.. But the other does, otherwise it's not created.. Would you happen to know why ? Here's my two types This one need the
ensure => present
to work (it's like if the ensure default value is not
present
)
Copy code
Puppet::Type.newtype(:powerdns_zone) do
  @doc = %q{
    @summary Configure and manage a PowerDNS zone
  }

  ensurable

  newparam(:value, namevar: true) do
    desc "The value  of the zone"
  end

  newparam(:nameservers) do
    desc "List of nameservers for the zone"
  end
end
This one does work without the need for the
ensure => present
Copy code
Puppet::Type.newtype(:powerdns_record) do
  @doc = %q{
    @summary Create and manage a PowerDNS record
  }

  ensurable

  newparam(:value, namevar: true) do
    desc "Value of the record"
  end

  newparam(:zone) do
    desc "Zone to which the record should be a part of"
  end

  newparam(:type) do
    desc "Type of the DNS record"
  end

  newparam(:target) do
    desc "Target to which the record should point to"
  end

  autorequire(:powerdns_zone) do
    self[:zone]
  end
end
t
Can you please provide the output of
puppet describe powerdns_zone
and
puppet describe powerdns_record
.
r
Absolutely ! powerdns_record
Copy code
powerdns_record
======================
@summary Create and manage a PowerDNS record


Parameters
----------

- **ensure**
    The basic property that the resource should be in.
    Valid values are `present`, `absent`.

- **target**
    Target to which the record should point to

- **type**
    Type of the DNS record
    Valid values are `A`, `AAAA`, `CNAME`, `SRV`, `NS`.

- **value** (*namevar*)
    Value of the record

- **zone**
    Zone to which the record should be a part of

Providers
---------
    ruby
powerdns_zone
Copy code
powerdns_zone
====================
@summary Configure and manage a PowerDNS zone


Parameters
----------

- **ensure**
    The basic property that the resource should be in.
    Valid values are `present`, `absent`.

- **nameservers**
    List of nameservers for the zone

- **value** (*namevar*)
    The value  of the zone
    Values can match `/^(?:[a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,63}\.$/`.

Providers
---------
    ruby
t
So both have ensure available. Can you please check if there is another module, which provides these types?
find /etc/puppetlabs/code/environments -type f -name powerdns_record.rb
and also for the other type?
I assume that
present
is the default if you use
ensurable
and: how do you deploy your new code?
Module in Puppetfile?
Is the type also in another environment?
do you run
puppet generate types
after r10k deployment?
r
Currently it's being deployed via an
auto-rsync
with Vagrant as I'm only starting to work on it.. But I'm sure that the code is properly deployed everytime ! I don't have any other file where the type is provided, only one file for each of my resources.. Yes I was also under the assumption that the
ensurable
would default to true.. and it seems to be doing it for one of the two resource, that's the strange part :')
Hello! Solved my issue with the following snippet :
Copy code
ensurable do
    defaultvalues
    defaultto :present
  end
Not sure how, or why, but now it works as expected!