Search code examples
puppet

"Invalid Resource Type" trying to use Puppet's Defined Resource Type


Puppet beginner here so maybe I'm doing something wrong...

I have a manifest that contains the following define

define amqconf (
    $activemq_home = '/opt/apache-activemq',
    $group         = 'activemq',
    $mode          = 0644,
    $owner         = 'activemq',
    $broker_name   = $title,
    $broker_port   = 61616,
) { 
    file { $title:
        ensure  => present,
        path    => "${activemq_home}/${broker_name}/conf/activemq.xml",
        content => template('profiles/activemq.xml.erb'),
    }
}

and then tries to use that define

$broker_conf = hiera('profiles::activemq::broker::conf')
create_resources( amqconf, $broker_conf )

but when I try and use this class I get the following error

Info: Using configured environment 'testing'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type amqconf at /etc/puppetlabs/code/environments/testing/modules/profiles/manifests/activemq.pp:73:5 on node cust-stage.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

What do I need to do in order to be able to use this define?

EDIT: added complete manifest

class profiles::activemq {

    include archive
    include profiles::java_7_oracle

    $activemq_version = '5.13.3'

    define amqconf (
        $activemq_home = '/opt/apache-activemq',
        $group         = 'activemq',
        $mode          = 0644,
        $owner         = 'activemq',
        $broker_name   = $title,
        $broker_port   = 61616,
    ) {
        file { $title:
            ensure  => present,
            path    => "${activemq_home}/${broker_name}/conf/activemq.xml",
            content => template('profiles/activemq.xml.erb'),
        }
    }

    group { 'activemq':
         ensure => present,
    }
    user { 'activemq':
        groups => 'activemq',
        comment => 'Service user for running the ActiveMQ service',
        home => "/opt/apache-activemq-$activemq_version",
        ensure => present,
        shell => '/bin/bash',
    }

    file { "/opt/apache-activemq-$activemq_version" :
        ensure => directory,
        owner  => 'activemq',
        group  => 'activemq',
        mode   => '0755',
    }
    archive { "/tmp/apache-activemq-$activemq_version-bin.tar.gz" :
        ensure        => present,
        source        => 'http://archive.apache.org/dist/activemq/5.13.3/apache-activemq-5.13.3-bin.tar.gz',
        checksum      => 'c19e2717f5c844a2f271fcd39eb024d04ebcfa5d',
        checksum_type => 'sha1',
        extract       => true,
        extract_path  => '/opt',
        creates       => "/opt/apache-activemq-$activemq_version/bin",
        cleanup       => true,
        user          => 'activemq',
        group         => 'activemq',
    }

    # Create the brokers defined in hiera.
    $brokers = hiera('profiles::activemq::brokers')
    $broker_defaults = {
        cwd   => "/opt/apache-activemq-${activemq_version}",
        group => 'activemq',
        user  => 'activemq',
    }
    create_resources( exec , $brokers, $broker_defaults )

    $broker_conf = hiera('profiles::activemq::broker::conf')
    create_resources( amqconf, $broker_conf )

}

Solution

  • I was never able to get the define to work in the class, but by placing it in its own file, I was able to get the define to work.

    amqconf.pp

    define profiles::amqconf (
        $activemq_home = '/opt/apache-activemq',
        $group         = 'activemq',
        $mode          = 0644,
        $owner         = 'activemq',
        $broker_name   = $title,
        $broker_port   = 61616,
        $broker_network_uri = 'NONE',
    ) {
        file { $title:
            ensure  => present,
            path    => "${activemq_home}/${broker_name}/conf/activemq.xml",
            content => template('profiles/activemq.xml.erb'),
        }
    }
    

    and then declaring it in activemq.pp

    profiles::amqconf { 'amq-1-conf' :
        broker_name   => 'amq-1',
        activemq_home => "/opt/apache-activemq-${activemq_version}",
    }
    

    The define works as expected.