Having trouble with create_resources

957 views
Skip to first unread message

Scott Rankin

unread,
Aug 30, 2011, 10:29:29 AM8/30/11
to puppet...@googlegroups.com
Hey all,

I'm running puppet 2.7.3 on CentOS, and am trying to use the new create_resources function.  I have a class that looks like this:

scp_account($userid, $unixid, $password) {
    .....
}

and I'm trying to call it with a hash of parameters like so:

# Create a hash of the scp accounts
$scp_accounts = {
    'joe' => {userid => 'joe', unixid => '700', password => '$1$sdfasdfasdfasdfsdaf'},
    'bob' => {userid => 'bob', unixid => '701', password => '$1$asdfsdfsadfasdfsadf'}
}
create_resources('scp_account', $scp_accounts)

However - when I try to run it, I'm getting an error like so:

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Must pass userid to Class[Production_scp_accounts::Scp_account] at /etc/puppet/modules/production_scp_accounts/manifests/scp_account.pp:1

I'm sure it's user error, but I'm having a hard time figuring out exactly what I'm doing wrong.

Thanks!

Scott Rankin

unread,
Aug 30, 2011, 11:55:33 AM8/30/11
to puppet...@googlegroups.com
Update - the above error was happening because I had left in an "include 'scp_account'" statement at the top.  I took that out, but now I'm running into this issue:

err: Could not retrieve catalog from remote server: Error 400 on SERVER: could not create resource of unknown type production_scp_accounts::scp_account 

My directory structure looks like this:

modules
    production_scp_accounts
        init.pp
        scp_account.pp

The create_resources call is in init.pp, in a class called "production_scp_accounts".  scp_account.pp has a class called "production_scp_accounts::scp_account", which I thought would be automatically picked up because I'm following the namespacing rules.  

Any thoughts? 

Nan Liu

unread,
Aug 30, 2011, 12:08:58 PM8/30/11
to puppet...@googlegroups.com

create_resource is for resources, not classes. Also if you change it
from a class to a define, the resource name in your example would be:
production_scp_acounts:scp_accounts. If you want a custom resource
called scp::account, your module layout should be:

modules
- scp
- manifests
- account.pp

define scp::account {
...
}

Thanks,

Nan

Scott Rankin

unread,
Aug 30, 2011, 12:17:25 PM8/30/11
to puppet...@googlegroups.com
I just figured that out.  If I change it to a defined resource, it works.  What led me in the wrong direction, though, was this sentence in the function documentation:  

" This is currently tested for defined resources, classes, as well as native types"

I guess that's not really the case?  

Nan Liu

unread,
Aug 30, 2011, 1:57:39 PM8/30/11
to puppet...@googlegroups.com
On Tue, Aug 30, 2011 at 12:17 PM, Scott Rankin <sdw...@gmail.com> wrote:
> I just figured that out.  If I change it to a defined resource, it works.
>  What led me in the wrong direction, though, was this sentence in the
> function documentation:
> " This is currently tested for defined resources, classes, as well as native
> types"
>
> I guess that's not really the case?

I need to be more precise about what I write, it will work for a class:

class hello_world {
notify { "hi": }
}

create_resource("class", {hello_world})

I should of wrote "in your case, create_resource is intended for
resources, not classes."

Thanks,

Nan

Reply all
Reply to author
Forward
0 new messages