Could not find parent resource type

571 views
Skip to first unread message

Raj kumar V

unread,
Nov 21, 2013, 4:11:01 AM11/21/13
to puppet...@googlegroups.com
I have written a module with a init class. Now I have to pass a dynamic value. so I have created a params class and inherited in the init class and trying to access the value. But puppet says 

Could not find parent resource type <myclass>::params of type hostclass 

error. Any idea? 

Felix Frank

unread,
Nov 21, 2013, 5:11:49 AM11/21/13
to puppet...@googlegroups.com
This looks pretty bad :-)

Can you paste (excerpts of) your manifest code on pastebin or a similar
service?

Raj kumar V

unread,
Nov 21, 2013, 6:17:35 AM11/21/13
to puppet...@googlegroups.com
In my module folder, <module/mymodule>

I have 2 files.

init.pp
params.pp

My init code:

class myclass($api_key=$myclass::params::myclassagent_APIkey) inherits myclass::params{

include myclass::params

some code here...

}include myclass

params.pp got:

class myclass::params{
myclassagent_APIkey=' '
}

What am i missing?

Felix Frank

unread,
Nov 21, 2013, 7:00:53 AM11/21/13
to puppet...@googlegroups.com
Hi,

comments inline.

On 11/21/2013 12:17 PM, Raj kumar V wrote:
> In my module folder, <module/mymodule>
>
> I have 2 files.
>
> init.pp
> params.pp
>
> My init code:
>
> class myclass($api_key=$myclass::params::myclassagent_APIkey) inherits
> myclass::params{

No need to inherit the params class. I would get rid of that first.

> include myclass::params

This is likely needed, although I'm not sure wether
$myclass::params::myclassagent_APIkey will already be available when
puppet encounters the class declaration header.

> some code here...
>
> }include myclass
>
> params.pp got:
>
> class myclass::params{
> myclassagent_APIkey=' '
> }

That looks all right, except for the missing $ on the variable name.

HTH,
Felix

Johan De Wit

unread,
Nov 21, 2013, 7:07:26 AM11/21/13
to puppet...@googlegroups.com
And to make autoloading work :

...modules/myclass/init.pp
/params.pp

hth

Jo
--
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer (805008667232363)
Puppet Certified Professional 2013 (PCP0000006)
_________________________________________________________

Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71
3071 KORTENBERG Mobile +32 (0)474/42 40 73
BELGIUM http://www.open-future.be
_________________________________________________________


Next Events:
Puppet Advanced Training | https://www.open-future.be/puppet-advanced-training-12-till-14th-november
Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-18-till-20th-november
Zabbix Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-21-till-22nd-november
Puppet Fundamentals Training | http://www.open-future.be/puppet-fundamentals-training-10-till-12th-december
Subscribe to our newsletter | http://eepurl.com/BUG8H

Raj kumar V

unread,
Nov 21, 2013, 7:24:27 AM11/21/13
to puppet...@googlegroups.com
Still the same error. I have the params in the same init location.

http://pastebin.com/nCmcgMi4

look at the pp scripts here....

Raj kumar V

unread,
Nov 21, 2013, 7:26:27 AM11/21/13
to puppet...@googlegroups.com
Warning: Scope(Class[<>]): Could not look up qualified variable '<>::params::<>_APIkey'; class <>::params could not be found

Warning: Scope(Class[<>]): Could not look up qualified variable '<>::params::<>_APIkey'; class <>::params could not be found
Error: Could not find class site24x7::params for <machine name>



On Thursday, 21 November 2013 14:41:01 UTC+5:30, Raj kumar V wrote:

Felix Frank

unread,
Nov 21, 2013, 7:39:15 AM11/21/13
to puppet...@googlegroups.com
Just a quick remark: If anonymisation is an issue for you, you should
definitely go back to pastebin and anynonymise the code there as well.

I notice some anti-patterns, but nothing stands out to me that should
make the agent fail like that...

Cheers,
Felix

jcbollinger

unread,
Nov 21, 2013, 8:59:37 AM11/21/13
to puppet...@googlegroups.com


On Thursday, November 21, 2013 6:07:26 AM UTC-6, Johan De Wit wrote:
And to make autoloading work :

...modules/myclass/init.pp
                              /params.pp



Make that
  modules/myclass/manifests/init.pp
and
  modules/myclass/manifests/params.pp
 

John

jcbollinger

unread,
Nov 21, 2013, 9:16:06 AM11/21/13
to puppet...@googlegroups.com


On Thursday, November 21, 2013 6:00:53 AM UTC-6, Felix.Frank wrote:
On 11/21/2013 12:17 PM, Raj kumar V wrote:
> In my module folder, <module/mymodule>
>
> I have 2 files.
>
> init.pp
> params.pp
>
> My init code:
>
> class myclass($api_key=$myclass::params::myclassagent_APIkey) inherits
> myclass::params{

No need to inherit the params class. I would get rid of that first.


I'm afraid there is a reason: class myclass uses a variable from class myclass::params as the default value for its class parameter.  The only self-contained way to ensure that that variable's value is already set when class myclass is evaluated is to inherit from myclass::params.  I don't like that much, but it has become a widely-used pattern.

 

> include myclass::params

This is likely needed, although I'm not sure wether
$myclass::params::myclassagent_APIkey will already be available when
puppet encounters the class declaration header.


That's absolutely unneeded if the class inherits from myclass::params, as shown.  On the other hand, it would be needed and appropriate if the body of class myclass used any variables of class myclass::params and myclass did not inherit from myclass::params.
 


> some code here...
>
> }include myclass


I'm not very comfortable with putting that 'include' statement at top level of the module's init.pp.  I think I understand the idea, but it could lead to subtle errors.  In fact, it leaves you in the realm of undocumented behavior if you ever try to declare class myclass elsewhere via a parameterized-style declaration (not that I generally account parameterized-style class declarations a good idea, but that seems the direction this is heading).


John

Reply all
Reply to author
Forward
0 new messages