Puppet

重複聲明:Exec已在定義類型中聲明

  • December 17, 2014

請幫助我解決我遇到的問題,我正在嘗試使用 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"

這是我的木偶腳本 instance.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,
   }

哦,那很難讀!

你真的應該努力,使用puppet-lint.

關鍵問題是這樣的:

Duplicate declaration: Exec[] is already declared in file

注意那是怎麼說的Exec[]

它應該包含 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}": }

您必須使用該格式。

引用自:https://serverfault.com/questions/653139