傀儡初学者在这里也许我做错了什么......
我有一个包含以下定义的清单
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'),
}
}
然后尝试使用该定义
$broker_conf = hiera('profiles::activemq::broker::conf')
create_resources( amqconf, $broker_conf )
但是当我尝试使用这个类时,我收到以下错误
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
为了能够使用此定义,我需要做什么?
编辑:添加完整清单
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 )
}
答案 0 :(得分:4)
我从来没有能够让定义在类中工作,但是通过将它放在自己的文件中,我能够使定义工作。
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'),
}
}
然后在activemq.pp中声明它
profiles::amqconf { 'amq-1-conf' :
broker_name => 'amq-1',
activemq_home => "/opt/apache-activemq-${activemq_version}",
}
定义按预期工作。