傀儡执行命令与variables未执行

我有一个非常简单的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] 

我尝试了${location}以及$location ,但结果保持不变。

你的第一个问题是你的command参数被单引号( ' )包围,这会抑制variables扩展。 如果你有:

 $location = "/path/to/target" 

然后:

 file { '$location': ensure => directory, } 

将尝试创build一个名为“ $location ”的目录,而这个:

 file { "$location": ensure => directory, } 

实际上会尝试创build/path/to/target

考虑到这一点,你的exec资源可能应该是这样的:

 exec { 'git-wp': command => "git clone https://github.com/WordPress/WordPress ${location}", require => Package['git'], } 

另外,不需要预先创build目标目录; git会为你做这个。

您可以使用--debug运行木偶,以查看由git输出的实际错误消息。