Puppet
未執行變數的 Puppet exec 命令
我有一個非常簡單的 Puppet(子)模組,應該使用 Git 從遠端位置複製儲存庫:
class wppuppet::git( $location = '/var/www/wp' ) { file { $location: ensure => 'directory', mode => '0755', } exec { 'git-wp': command => 'git clone https://github.com/WordPress/WordPress ${location}', require => Package['git'], } Package['git'] -> File[ $location ] -> Exec['git-wp'] }
由於某種原因,它不斷失敗並出現以下錯誤:
Error: git clone https://github.com/WordPress/WordPress ${location} returned 128 instead of one of [0] Error: /Stage[main]/Wppuppet::Git/Exec[git-wp]/returns: change from notrun to 0 failed: git clone https://github.com/WordPress/WordPress ${location} returned 128 instead one of [0]
我嘗試了 with
${location}
以及 with$location
,但結果保持不變。
您的第一個問題是您的
command
參數用單引號 ('
) 括起來,這會抑制變數擴展。如果你有:$location = "/path/to/target"
然後:
file { '$location': ensure => directory, }
將嘗試創建一個名為“
$location
”的目錄,而這:file { "$location": ensure => directory, }
實際上會嘗試創建
/path/to/target
.考慮到這一點,您的
exec
資源應該如下所示:exec { 'git-wp': command => "git clone https://github.com/WordPress/WordPress ${location}", require => Package['git'], }
此外,不需要預先創建目標目錄;
git
會為你做這件事。您可以執行 puppet
--debug
以查看git
.