Puppet unable to find a defined resource.

4,444 views
Skip to first unread message

Brad Krane

unread,
Aug 19, 2011, 2:33:01 PM8/19/11
to Puppet Users
Hi,

I've been stumped by the following error for quite a while now it is
generated when running the manifest further below:

err: Could not retrieve catalog from remote server: Error 400 on
SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError:
Invalid resource type drupal6::theme_repo at srv/puppet/modules/
drupal6/manifests/init.pp:129 on node www-cms-dev.fs.uwaterloo.ca


site.pp
----------

class web_cms_dev_server inherits debian_server {
include apache2
include drupal6
include drupal6::dev
}


drupal6/manifests/init.pp
------------------------------------

$d6_confpath = "/usr/share/drupal6"
$d6_scriptpath = "/usr/share/drupal6"
$gitdir = "/srv/git/drupal-themes"

class drupal6 {
include apache2::rewrite
include mysql

# Resources to mount the dev repo share for the drupal themes git
repo and clone and track it
package { "git-core":
ensure => present
}
file { "/srv/git":
ensure => "directory",
owner => "root",
group => "itstaff",
mode => 0755
}
mount { "/srv/git":
device => "file-nfs.fs.uwaterloo.ca:/srv/git",
options => "_netdev,rw,hard,fg,lock,nfsvers=3,tcp",
fstype => "nfs",
ensure => mounted,
require => File["/srv/git"]
}

# Use drupal short name as module name to install
define module ( $ensure = 'present', $site = 'all') {
case $ensure {
'present': {
# TODO: change the exec below to use the script to
test for the module when it has the capability to do so
# Creates test may not work but does for modules
listed as of commit 3379078fc1d66830d8a88caff42eae2566c4650b
2010-02-03
exec { "install-module-${name}-site-${site}":
creates => "${d6_confpath}/sites/${site}/modules/$
{name}",
#command => "drupal-module -d ${d6_confpath}/sites/
${site}/modules -i ${name}",
command => "drush -r ${d6_confpath} dl ${name}",
timeout => 1500,
}

if $require {
Exec["install-module-${name}-site-${site}"] {
require +> [$require, Package["archive-tar-
minitar"], Package["drupal6"], Package["drush"]]
}
} else {
Exec["install-module-${name}-site-${site}"] {
require => [Package["archive-tar-minitar"],
Package["drupal6"], Package["drush"]]
}
}
}
'absent': {
# TODO: change the exec below to use the script to
remove the modules when it can
exec { "remove-module-${name}-site-${site}":
onlyif => "test -d ${d6_confpath}/sites/${site}/
modules/${name}",
command => "rm -rf ${d6_confpath}/sites/${site}/
modules/${name}"
}
}
}
}

# Web developer themes repo
# theme: name of the theme
# version: name of the git tag for the desired version
# upstream: the source url for the git repo. If false a local repo
in $gitdir/$theme is assumed
# site: the site this theme is applied to
# Local changes sould be put on the feds branch which should be
rebased onto newer versions
define theme_repo(
$theme = "",
$version = "",
$site = "default",
$upstream = "drupal")
{
case $upstream {
# Custom theme, no upstream create an empty bare repo
false: {
git::repository { "bare repo $site-$theme":
real_name => "$theme",
localtree => $gitdir,
shared => true,
owner => "root",
group => "webdeveloper",
require => Mount["/srv/git"],
before => Git::Clone["$site theme $theme-
$version"]
}
}
# Drupal.org theme, clone from upstream
"drupal": {
exec { "clone from upstream $site-$theme":
cwd => $gitdir,
command => "git clone --bare http://git.drupal.org/project/$theme.git
$site-$theme && chown -R root:webdeveloper $site-$theme && chmod -R ug
+w $site-$theme",
onlyif => "test ! -d $gitdir/$site-$theme",
before => Git::Clone["$site theme $theme-
$version"]
}
}
# Custom upstream theme
default: {
exec { "clone from upstream $site-$theme":
cwd => $gitdir,
command => "git clone --bare $upstream $site-
$theme && chown -R root:webdeveloper $theme && chmod -R ug+w $theme",
onlyif => "test ! -d $gitdir/$site-$theme",
before => Git::Clone["$site theme $theme-
$version"]
}
}
}

if $upstream != false {
exec { "setup $site $theme upstream at $version and feds
branch":
cwd => "/srv/drupal/$site/themes/$theme",
command => "git branch v${version} refs/tags/$
{version} && git checkout v${version} && git branch feds && git
checkout feds",
refreshonly => true,
}
}

# Clone a working dir to Drupal site themes dir
git::clone { "$site theme $theme-$version":
source => "$gitdir/$site-$theme",
localtree => "/srv/drupal/$site/themes",
real_name => "$theme",
require => [Package["git-core"], Mount["/srv/git"], File["/
srv/drupal/$site"]],
notify => Exec["setup $site $theme upstream at $version
and feds branch"]
}
}

# Testing
define alt_site ($theme) {
drupal6::theme_repo { "$name-$theme['name']":
theme => $theme['name'],
version => $theme['version'],
upstream => $theme['upstream'],
site => "default"
}
} #
<---------------------------------------- Line 129

# Drupal site definition
# In a multi-site setup, for sites other than default the name
# of drupal6::site must be the domain/subdomain of the site
# siteAlias can be a string or array of strings. www. prefixes are
added automatically.
define site (
$ensure = 'present',
$dbname,
$dbpw,
$dbserver,
$sitefqdn,
$siteAlias = "",
$modules = "",
$nagios_uid,
$nagios_timeout = 5,
) {
case $ensure {
'present': {
apache2::site { $sitefqdn:
ensure => 'present',
sitePath => "${d6_scriptpath}",
content => template("drupal6/vhost.erb"),
require => Package["drupal6"]
}

# Export a db
mysql::database { $dbname:
passwd => $dbpw,
server => $dbserver,
fqdn => $fqdn
}


file {
"${d6_confpath}/sites/${name}/dbconfig.php":
mode => 0440,
owner => "www-data",
group => "www-data",
content => template("drupal6/
dbconfig.php.erb"),
require => File["${d6_confpath}/sites/$
{name}"];
"${d6_confpath}/sites/${name}/settings.php":
mode => 0440,
owner => "www-data",
group => "www-data",
content => template("drupal6/
settings.php.erb"),
require => [File["${d6_confpath}/sites/$
{name}"], Exec["create-database-tables-${name}"]];
"${d6_confpath}/sites/${name}/files":
ensure => "/srv/drupal/${name}/files",
force => true,
backup => false,
require => [File["/srv/drupal/${name}/files"],
File["${d6_confpath}/sites/${name}"]];
"${d6_confpath}/sites/${name}/themes":
ensure => "/srv/drupal/${name}/themes",
force => true,
backup => false,
require => [File["/srv/drupal/${name}/
themes"], File["${d6_confpath}/sites/${name}"]];
"${d6_confpath}/sites/${name}/modules":
ensure => directory,
mode => 775,
owner => "www-data",
group => "www-data",
require => File["${d6_confpath}/sites/$
{name}"];
"${d6_confpath}/sites/${name}/tmp":
ensure => directory,
mode => 775,
owner => "www-data",
group => "www-data",
require => File["${d6_confpath}/sites/$
{name}"];
"/srv/drupal/${name}/files":
ensure => directory,
mode => 0775,
owner => "www-data",
group => "www-data",
require => File["/srv/drupal/${name}"];
"/srv/drupal/${name}/themes":
ensure => directory,
mode => 0775,
owner => "www-data",
group => "www-data",
require => File["/srv/drupal/${name}"];
"/srv/drupal/${name}":
ensure => directory,
mode => 0775,
owner => "www-data",
group => "www-data",
require => File["/srv/drupal"];
"${d6_confpath}/sites/${name}":
ensure => directory,
mode => 0555,
owner => "www-data",
group => "www-data";
}

# You must visit http://${sitefqdn}/install.php to
complete the rest of the Drupal setup.
exec { "create-database-tables-${name}":
command => "wget -O ${d6_confpath}/sites/${name}/
database-created 'http://${sitefqdn}/install.php?profile=${name}
&locale=en'",
creates => "${d6_confpath}/sites/${name}/database-
created"
}

# cron job
exec { "${name}-cron":
command => "wget -O - -q -t 1 http://${sitefqdn}/cron.php"
}

if $require {
File["${d6_confpath}/sites/$name"] {
require +> [$require, Package["drupal6"]]
}
} else {
File["${d6_confpath}/sites/$name"] {
require => Package["drupal6"]
}
}

# Nagios Drupal site Monitor
if $nagios_uid {
@@nagios_service { "Drupal-$fqdn-$sitefqdn":
use => "feds-generic-service",
host_name => "$fqdn",
servicegroups => "services",
service_description => "Drupal-${sitefqdn}",
check_command => "check_drupal!${sitefqdn}!$
{nagios_uid}!${nagios_timeout}",
contact_groups => "itstaff",
target => "/etc/nagios3/conf.d/service_${fqdn}
_Drupal_${sitefqdn}.cfg"
}
}
} # 'present'
} # case $ensure
} # site

# Initial Installation Stuff
package { ["drupal6", "drush", "unzip", "php5-curl"]:
ensure => present,
require => [Mount["/srv"], User["www-data"], Group["www-
data"], Package["postfix"]]
}
package { "archive-tar-minitar":
ensure => present,
provider => gem
}

file {
"/srv/drupal":
ensure => directory,
mode => 775,
owner => "www-data",
group => "www-data",
require => Package["drupal6"];
}

file {
"${d6_confpath}/sites/all":
ensure => directory,
mode => 0555,
owner => "www-data",
group => "www-data",
require => Package["drupal6"];
"${d6_confpath}/sites/all/libraries":
ensure => directory,
mode => 0555,
owner => "www-data",
group => "www-data",
require => File["${d6_confpath}/sites/all"];
"${d6_confpath}/sites/all/modules":
ensure => directory,
mode => 0555,
owner => "www-data",
group => "www-data",
require => File["${d6_confpath}/sites/all"];
}

}



drupal6/manifests/dev.pp
------------------------------------

class drupal6::dev {
package { "php5-imap": }

file { "/srv/git/drupal-themes":
ensure => directory,
owner => root,
group => webdeveloper,
mode => 0775,
require => Mount["/srv/git"]
}

package {["subversion", "git-svn", "ack-grep"]:
ensure => present
}


drupal6::module { ["fb", "computed_field"]: }

drupal6::site { "default":
dbname => "dev-drupal",
dbpw => "XXXXXXXXXXXXX",
dbserver => "db.fs.uwaterloo.ca",
sitefqdn => "dev-drupal.feds.ca",
nagios_uid => "XXXXXXXXXXXX",
}

drupal6::alt_site { "random_test":
theme => { "name" => "zen", version => "6.x-2.0", "upstream"
=> "drupal" }
}

}


Both the drupal6::modules and the drupal6::site are referenced and
created fine however the drupal6::alt_site is not.

I've checked everything that I can think of but can't come up with why
I can't have what is essentially:

node 'dev' {
include d6
include d6::dev
}

class d6 {
define site_theme {
....
}

define site {
....
site_theme { "theme": }
}
}

class d6::dev {
d6::site { "site"; }
}

Any help or insight is very much appreciated.



jcbollinger

unread,
Aug 22, 2011, 9:58:23 AM8/22/11
to Puppet Users


On Aug 19, 1:33 pm, Brad Krane <brad.kr...@gmail.com> wrote:

[...]

> drupal6/manifests/init.pp
> ------------------------------------

[...]

> class drupal6 {

[...]

>     define theme_repo(
>         $theme = "",
>         $version = "",
>         $site = "default",
>         $upstream = "drupal")
>     {

[...]

>     }
>
>     # Testing
>     define alt_site ($theme) {
>         drupal6::theme_repo { "$name-$theme['name']":
>               theme => $theme['name'],
>               version => $theme['version'],
>               upstream => $theme['upstream'],
>               site => "default"
>           }
>     }                                     #
> <---------------------------------------- Line 129

[...]

> Any help or insight is very much appreciated.

It looks to me like the correct fully-qualified name of the define
should be drupal6::drupal6::theme_repo. If you want it to be just
drupal6::theme_repo then put it in its own file (named modules/drupal6/
manifests/theme_repo.pp). You definitely should do so if you
anticipate that the define will be used anywhere other than where it
already is used. You also the option of refering to the define by its
simple name ("theme_repo") within the scope where it is declared.


John

Brad Krane

unread,
Aug 22, 2011, 3:58:31 PM8/22/11
to Puppet Users
John,

Thanks for the reply. I've tried all of your suggestions above,
qualifying it as drupal6::drupal6::theme_repo and just theme_repo as
well as putting the definition in its own file modules/drupal6/
manifests/theme_repo.pp (and also using the three combinations of
variable scoping) but I always get a similar result that it cannot
find the resource.

This behavior is very odd to me as I've used very similar definitions
where they include other definitions of the same manifest with no
issue at all but it seems that for whatever reason specifically with
this module I get an error when I do so.

jcbollinger

unread,
Aug 25, 2011, 10:01:33 AM8/25/11
to Puppet Users


On Aug 22, 2:58 pm, Brad Krane <brad.kr...@gmail.com> wrote:
> John,
>
> Thanks for the reply. I've tried all of your suggestions above,
> qualifying it as drupal6::drupal6::theme_repo and just theme_repo as
> well as putting the definition in its own file modules/drupal6/
> manifests/theme_repo.pp (and also using the three combinations of
> variable scoping) but I always get a similar result that it cannot
> find the resource.
>
> This behavior is very odd to me as I've used very similar definitions
> where they include other definitions of the same manifest with no
> issue at all but it seems that for whatever reason specifically with
> this module I get an error when I do so.


Then let's take a step back. Your class is rather complicated, and
all the details may be confusing (or even causing) the issue. For
example, you may have a nesting problem that is difficult to see in
all that code. I suggest putting each 'define' in its own file to
help make things clearer and more maintainable. Even before that,
however, I suggest getting a much simplified stub working, then
fleshing it out. So, does this work for you:

drupal6/manifests/init.pp
-----------------------------------
class drupal6 {
drupal6::theme_repo { "foo": }
}


drupal6/manifests/theme_repo.pp
------------------------------------------------
define theme-repo() {
}


?

Brad Krane

unread,
Sep 2, 2011, 1:54:52 PM9/2/11
to Puppet Users

> Then let's take a step back.  Your class is rather complicated, and
> all the details may be confusing (or even causing) the issue.  For
> example, you may have a nesting problem that is difficult to see in
> all that code.  I suggest putting each 'define' in its own file to
> help make things clearer and more maintainable.  Even before that,
> however, I suggest getting a much simplified stub working, then
> fleshing it out.  So, does this work for you:
>
> drupal6/manifests/init.pp
> -----------------------------------
> class drupal6 {
>   drupal6::theme_repo { "foo": }
>
> }
>
> drupal6/manifests/theme_repo.pp
> ------------------------------------------------
> define theme-repo() {
>
> }
>
> ?


Ok, I took a big, big step back, broke out all of the drupal6::site,
drupal6::theme-repo and drupal6::module into their own files. I also
reduced the complexity of the module by stubbing out all the
definitions to contain almost nothing. Here is what I have left:

drupal6/manifests/init.pp
-------------------------------------
$d6_confpath = "/usr/share/drupal6"
$d6_scriptpath = "/usr/share/drupal6"
$gitdir = "/srv/git/drupal-themes"

class drupal6 {

}

drupal6/manifests/module.pp
-------------------------------------
define drupal6::module ( $ensure = 'present', $site = 'all') {
notice("module")
}

drupal6/manifests/site.pp
-------------------------------------
define drupal6::site (
$ensure = 'present',
$dbname,
$dbpw,
$dbserver,
$sitefqdn,
$siteAlias = "",
$modules = "",
$nagios_uid,
$nagios_timeout = 5,
$theme = { "name" => nil, "version" => nil, "upstream" =>
"drupal" }
) {
case $ensure {
'present': {

drupal6::module { "module":
}

# Site theme
drupal6::theme-repo { "$name-$theme['name']":
}

} # 'present'
} # case $ensure
}

drupal6/manifests/theme-repo.pp
-------------------------------------
define drupal6::theme-repo()
{
notice("theme-repo")
}


And I still get the same error below.

err: Could not retrieve catalog from remote server: Error 400 on
SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError:
Invalid resource type drupal6::theme-repo at srv/puppet/modules/
drupal6/manifests/site.pp:19 on node www-cms-dev.fs.uwaterloo.ca


That is until I removed $theme['name'] from the drupal6::theme-repo's
name! It looks like having set theme['name'] = nil as the default
value and not setting it to a non-nil value caused the error.


Brad Krane

unread,
Sep 2, 2011, 2:10:43 PM9/2/11
to Puppet Users
I have spoken too soon about the nil value causing the problem. When I
set the default value from nil to "something" the error came back. It
seems that just using a hash value in the name to be expanded is what
the real issue is.

Brad Krane

unread,
Sep 2, 2011, 2:21:54 PM9/2/11
to Puppet Users
Here is a very simple manifest that recreates this error:


class foo {
define bar ( $val ) {
notice("bar($val)")
}
}

$some_hash = { 'name' => "some_name" }

foo::bar { "$some_hash['name']": }


Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid
resource type foo::bar at /tmp/puptest.pp:9 on node www-cms-
dev.fs.uwaterloo.ca


This seems like a bug to me.

Paul Nguyen

unread,
Sep 2, 2011, 7:28:57 PM9/2/11
to puppet...@googlegroups.com
I'm also seeing the same problem I believe.

I'm running on the following

puppet 2.7.3
ruby 1.8.5
centos 5

I have a defined resource in the module called accounts

   class accounts::virtual {
     define createsysuser ($val) {
         ...
     }
   }

In another class in the same module, I have the following

  class accounts::appaccts {
    include account::virtual

    createsysuser { "someuser"
       val => "someuser"
    }
  }

I get the following error

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type createsysuser at /etc/puppet/modules/accounts/manifests/applications.pp:6 on node foobar.test.com

Is there a fix for this, or am I doing something wrong?

Thanks,
Paul


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.


jcbollinger

unread,
Sep 6, 2011, 9:17:40 AM9/6/11
to Puppet Users
There is at minimum a documentation bug (the docs don't discuss
whether or how to interpolate hash values) and a bug / needed feature
regarding the extremely unhelpful error message. I'm not sure whether
it's supposed to work to interpolate a hash value as you are
attempting to do (and I don't recall offhand whether you can
interpolate array elements either), but supporting that is at least a
viable feature request.

In the mean time, there are at least two workarounds I can think of.
One is to use an inline template to do your interpolation, and another
is to copy the hash value into an ordinary variable and then
interpolate that. I would personally prefer the latter in most
circumstances; I find it clearer, especially if I need the hash value
more than once:

$theme_name = $theme['name']

# Site theme
drupal6::theme-repo { "${name}-${theme_name}":
}


Note also that there's a better solution for your simplified example,
where the string you want is exactly the hash value: just omit the
quotes. To wit,

foo::bar { $some_hash['name']: }


John

Brad Krane

unread,
Sep 7, 2011, 4:11:45 PM9/7/11
to Puppet Users
Paul,

I'm not exactly sure, but from your class setup it looks like the
createsysuser resource would have the full scope of
accounts::virtual::createsysuser and should be referenced by
virtual::createsysuser and not just createsysuser when it is used in
accounts::appaccts.

Cheers,

Paul Nguyen

unread,
Sep 12, 2011, 8:15:26 PM9/12/11
to puppet...@googlegroups.com
Brad.

Using the virtual::createsysuser worked. 

Thanks again,
Paul
Reply all
Reply to author
Forward
0 new messages