重复声明:Exec[] 已在定义类型中声明

重复声明:Exec[] 已在定义类型中声明

请帮助我解决我遇到的问题,我正在尝试使用 puppet 脚本安装 adobe CQ5(作者/发布模式)。我已将 instance.pp 定义为定义类型并在清单文件中传递(作者、发布)参数。但我收到下面提到的错误

"Duplicate declaration: Exec[] is already declared in file /tmp/vagrant-puppet/modules-0/cq/manifests/instance.pp:55; cannot redeclare at /tmp/vagrant-puppet/modules-0/cq/manifests/instance.pp:62 on node localhost.123.176.37.38"

例如,这是我的木偶脚本。pp

define cq::instance (
$installation_type,
$servername = $name,
$sling_run_modes = "author,dev",
$data_dir = "/home/vagrant/$name",
$install_path = "/home/vagrant/{$name}/cq5",
$min_heap = '256',
$max_heap = '1024',
$perm_gen = '300',
$cq_jar = "cq-author-4502.jar",
$port_author = "4502",
$port_publish = "4503",)  


{


$cq_port = $installation_type ? {
"author" => $port_author,
"publish" => $port_publish,
default => "4502",
}

if $installation_type in [ author, publish ] {
$type_real = $installation_type
} 


else {
fail('installation_type parameter must be author or publish')
}

   file { "/tmp/$servername .${cq_jar}" :
     ensure => "present",
     source => "puppet:///modules/cq/${cq_jar}",
     owner  => vagrant,
     mode   => 755

     }


file { [ "$data_dir", "$install_path", "$install_path/$type_real" ]:
ensure  => "directory",
mode    => 0755,
before  =>  Exec ["$name_move_jar"],
}   
exec {"$name_move_jar":
require => File["/tmp/${cq_jar}"],
cwd => "/tmp",
command => "cp ${cq_jar} $install_path/$type_real",
creates => "$install_path/$type_real/$cq_jar"
}

exec {"$name_unpack_CQ_jar":
command => "java -jar $cq_jar -unpack",
cwd => "$install_path/$type_real",
creates => "$install_path/$type_real/crx-quickstart",
require => Exec["$name_move_jar"],
}

file {"$install_path/$type_real/crx-quickstart/bin":
ensure  => directory,
require => Exec["$name_unpack_CQ_jar"],
}
file {"$name_start_script":
path => "$install_path/$type_real/crx-quickstart/bin/start",
content => template('cq/cq_5_6_start.erb'),
mode => 0777,
require => File["$install_path/$type_real/crx-quickstart/bin"],
before  => File["initd_script_$type_real"],
}
file {"$name_initd_script_$type_real":
path => "/etc/init.d/cq-$type_real",
content => template('cq/cq_init_d_5_6.erb'),
mode => 0777,
}


service {"cq-$type_real":
ensure => running,
enable=>true,
hasrestart  => true,
hasstatus => true,
require => File["initd_script_$type_real"],
}
}

清单文件 site.pp 是

cq::instance {myauthor:
      installation_type => author,
    }

cq::instance {mypublish:
      installation_type => publish,
    }

答案1

哦,这太难读了!
你真的应该努力一下,使用puppet-lint

关键问题是这样的:

Duplicate declaration: Exec[] is already declared in file

注意看上面是怎么说的Exec[]
它应该包含执行者的名字,但是它没有。

exec {"$name_move_jar":

这会将名称设置为变量$name_move_jar
这不是您想要的。
您想要${name}_move_jar
您确实应该使用${name}样式变量。

使用花括号可以非常清楚地表明哪些部分仍然是变量名的一部分,哪些不是。
功能上没有区别,它只是告诉解析器更具体的变量名称。
例如:

notify { "$foo-bar": }

很难说清楚这里的变量是什么。是 吗$foo-bar?还是只是$foo
那个例子是$foo(变量名中不允许使用破折号)。
为了避免混淆,最好改写${foo}-bar
每个人都知道那${foo}是变量。

如果需要将变量连接到字符串,例如:

notify { "${var1}${var2}": }

您必须使用该格式。

相关内容