Why i cant change my custom types?

31 views
Skip to first unread message

Akai

unread,
Nov 8, 2016, 5:58:58 AM11/8/16
to Puppet Users
Hello Together,

i have a strange behaviour wich i cant explain myself. I want to create a new custom type (and later a provider) who can configure our own created software. For this, i createt a test module and put there everything for my development. It looks like this

.
├── lib
  └── puppet
      ├── provider
      └── type
          └── custom_type.rb
└── manifests
   
└── init.pp


In Module development, my steps would be this:

1. Make changes
2. appy on a node
3. Make changes
4. ...

But if i apply a module who uses a custom type, i only can make changes until i never use this custom type on a puppetmaster before. It looks like, the puppetmaster "remembers" the custom type and every change results in a failure. If i reset my puppetmaster, add the changed custom type, everything works fine. Let explain me this in code, because my english is not so good:

For example i have a very emtpy custom_type

Puppet::Type.newtype(:custom_type) do
  newparam
(:name) do
    isnamevar
 
end
 
end

and the init.pp from my module looks like this:

class type_test{

       custom_type
{ 'aname':
       
}
}

It works fine if i apply this.

When i add now a  new parameter for example:

Puppet::Type.newtype(:custom_type) do
  newparam
(:name) do
    isnamevar
 
end

  newparam
(:envid) do
   
# validate is tring or false
    validate
do |value|
     
unless value.is_a?(String)
       
raise Puppet::Error, 'Parameter envid is not a string.'
     
end
   
end
 
end
end

and i apply this by the new init.pp

class type_test{
        custom_type
{ 'aname':
            envid
=> '78121-1239-0000-1231',
       
}
}

he gives me the following failure:

Could not retrieve catalog from remote server: Error 400 on SERVER: Invalid parameter envid on custom_type[aname] at /etc/puppet/environments/development/modules/type_test/manifests/init.pp:8 on node xyz

The strange this is: If i reset now my puppetmaster on a older snapshot and apply the new version of my custom_type.rb and init.pp again. everything works fine. I have this on every change, for example, adding more parameters, propertys or even i make it ensurable.

It cant be the right way, to always reset everythng on a older snapshot or? Why the puppetmaster "rembers" the custom_type definition and does not accept changes? How i handle this?

Thanks for any help

Akai

David Schmitt

unread,
Nov 8, 2016, 6:27:58 AM11/8/16
to Puppet Users


On Tuesday, November 8, 2016 at 10:58:58 AM UTC, Akai wrote:
It cant be the right way, to always reset everythng on a older snapshot or? Why the puppetmaster "rembers" the custom_type definition and does not accept changes? How i handle this?

Since custom types are native ruby code, the puppetserver is restricted in what it can do with it. Once the code is loaded into the process, it remains there. To get rid of it without trashing your whole environment, restart the puppetserver service. The newly started puppetserver will read the custom type afresh and have the new code then available for your testing.


Cheers, David

Akai

unread,
Nov 8, 2016, 7:31:07 AM11/8/16
to Puppet Users
Hello David,

thank you for this explanation. Everything could be so simple. Now i understand :-) ...

Best Regards

David Schmitt

unread,
Nov 8, 2016, 9:30:45 AM11/8/16
to Puppet Users
Another thing you might want to try is "puppet generate type", a experimental feature of puppet 4.6 onwards: https://docs.puppet.com/puppet/4.8/reference/environment_isolation.html

Regards, David
Reply all
Reply to author
Forward
0 new messages