无法使用 Puppet 签出 SVN 存储库
Unable to checkout SVN repo using Puppet
我正在尝试从我接受 URL 作为参数的 SVN 存储库中检出代码。我引用了 URL 如下所示,因为它包含空格。我还通过重定向文件中的 $svn_url
检查了参数(如下所示)。如果我从文件中选择 URL 并将其 按原样 在命令行上传递给给定的脚本,它工作正常但不知何故当从 Puppet 调用时,它不起作用。
人偶显现:
repo_checkout.pp
:
define infra::svn::repo_checkout ($svn_url_params) {
$svn_url = $svn_url_params[svn_url]
include infra::params
$repo_checkout_ps = $infra::params::repo_checkout_ps
file { $repo_checkout_ps:
ensure => file,
source => 'puppet:///modules/infra/repo_checkout.ps1',
}
util::executeps { 'Checking out repo':
pspath => $repo_checkout_ps,
argument => "\'\"$svn_url\"\'",
}
}
params.pp
:
$repo_checkout_ps = 'c:/scripts/infra/repo_checkout.ps1',
site.pp
:
$svn_url_ad = {
svn_url => 'https:\\some_repo.abc.com\svn\dir with space\util',
}
infra::svn::repo_checkout { "Checking out code in C:\build":
svn_url_params => $svn_url_ad
}
executeps.pp
:
define util::executeps ($pspath, $argument) {
$powershell = 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NoLogo -NonInteractive'
exec { "Executing PS file \"$pspath\" with argument \"$argument\"":
command => "$powershell -file $pspath $argument",
timeout => 900,
}
}
PowerShell 代码:
$svn_url = $args[0]
Set-Location C:\build
echo "svn co --username user --password xxx --non-interactive '$svn_url'" | Out-File c:\svn_url
svn co --username user --password xxx --non-interactive '$svn_url'
代理节点上的 Puppet 输出:
Util::Executeps[Checking out repo]/Exec[Executing PS file "c:/scripts/infra/repo_checkout.ps1" with argument "'"https:\some_repo.abc.com\svn\dir with space\util"'"]/returns: executed successfully
Notice: Applied catalog in 1.83 seconds
c:\svn_url
的内容:
'https:\\some_repo.abc.com\svn\dir with space\util'
更新:很抱歉造成混淆,但我尝试了几种排列和组合,在这样做的过程中,我忘了提到当 $svn_url
包含反斜杠 (\)
时,它会 NOT 如果我从我重定向 echo
输出的文本文件中复制 SVN URL,那么也不能在命令行上工作。
根据@Ansgar 的建议,我在 powershell 代码中将 '$svn_url'
更改为 "$svn_url"
,但文本文件中的输出随后包含 '
引用 两次 围绕 URL。所以我将 argument
参数从 "\'\"$svn_url\"\'"
更改为 "\"$svn_url\""
。现在输出文件在 URL 两边只有单引号。我只从输出文件中复制了 URL(连同它周围的单引号)并尝试将其传递给 powershell 脚本。我现在收到以下错误:
svn: E020024: Error resolving case of 'https:\some_repo.abc.com\svn\dir with space\util'
另一件需要注意的事情是,如果我将 URL 中的反斜杠更改为正斜杠,它在命令行上 fine 有效。从 Puppet 调用仍然无效。
发布根据@AnsgarWiechers 的建议为我制定的最终配置。
[tom@pe-server] cat repo_checkout.pp
define infra::svn::repo_checkout ($svn_url_params) {
$svn_url = $svn_url_params[svn_url]
...
...
util::executeps { 'Checking out repo':
pspath => $repo_checkout_ps,
argument => "\"$svn_url\"",
}
}
[tom@pe-server] cat repo_checkout.ps1
$svn_url = $args[0]
Set-Location C:\build
svn co --username user --password xxx --non-interactive "$svn_url"
[tom@pe-server] cat params.pp
$repo_checkout_ps = 'c:/scripts/infra/repo_checkout.ps1',
[tom@pe-server] cat site.pp
$svn_url_ad = {
svn_url => 'https://some_repo.abc.com/svn/dir with space/util',
}
infra::svn::repo_checkout { "Checking out code in C:\build":
svn_url_params => $svn_url_ad
}
非常感谢@AnsgarWiechers! :)
注:
- 在 site.pp 中:在指定
svn_url
时使用正斜杠 (/)
- 在 repo_checkout.ps1 中:将
'$svn_url'
更改为 "$svn_url"
- 在 repo_checkout.pp 中:将
argument
中的双嵌套('
和 "
)引用更改为单引用("
) 嵌套,即从 "\'\"$svn_url\"\'"
到 "\"$svn_url\""
我正在尝试从我接受 URL 作为参数的 SVN 存储库中检出代码。我引用了 URL 如下所示,因为它包含空格。我还通过重定向文件中的 $svn_url
检查了参数(如下所示)。如果我从文件中选择 URL 并将其 按原样 在命令行上传递给给定的脚本,它工作正常但不知何故当从 Puppet 调用时,它不起作用。
人偶显现:
repo_checkout.pp
:
define infra::svn::repo_checkout ($svn_url_params) {
$svn_url = $svn_url_params[svn_url]
include infra::params
$repo_checkout_ps = $infra::params::repo_checkout_ps
file { $repo_checkout_ps:
ensure => file,
source => 'puppet:///modules/infra/repo_checkout.ps1',
}
util::executeps { 'Checking out repo':
pspath => $repo_checkout_ps,
argument => "\'\"$svn_url\"\'",
}
}
params.pp
:
$repo_checkout_ps = 'c:/scripts/infra/repo_checkout.ps1',
site.pp
:
$svn_url_ad = {
svn_url => 'https:\\some_repo.abc.com\svn\dir with space\util',
}
infra::svn::repo_checkout { "Checking out code in C:\build":
svn_url_params => $svn_url_ad
}
executeps.pp
:
define util::executeps ($pspath, $argument) {
$powershell = 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NoLogo -NonInteractive'
exec { "Executing PS file \"$pspath\" with argument \"$argument\"":
command => "$powershell -file $pspath $argument",
timeout => 900,
}
}
PowerShell 代码:
$svn_url = $args[0]
Set-Location C:\build
echo "svn co --username user --password xxx --non-interactive '$svn_url'" | Out-File c:\svn_url
svn co --username user --password xxx --non-interactive '$svn_url'
代理节点上的 Puppet 输出:
Util::Executeps[Checking out repo]/Exec[Executing PS file "c:/scripts/infra/repo_checkout.ps1" with argument "'"https:\some_repo.abc.com\svn\dir with space\util"'"]/returns: executed successfully Notice: Applied catalog in 1.83 seconds
c:\svn_url
的内容:
'https:\\some_repo.abc.com\svn\dir with space\util'
更新:很抱歉造成混淆,但我尝试了几种排列和组合,在这样做的过程中,我忘了提到当 $svn_url
包含反斜杠 (\)
时,它会 NOT 如果我从我重定向 echo
输出的文本文件中复制 SVN URL,那么也不能在命令行上工作。
根据@Ansgar 的建议,我在 powershell 代码中将 '$svn_url'
更改为 "$svn_url"
,但文本文件中的输出随后包含 '
引用 两次 围绕 URL。所以我将 argument
参数从 "\'\"$svn_url\"\'"
更改为 "\"$svn_url\""
。现在输出文件在 URL 两边只有单引号。我只从输出文件中复制了 URL(连同它周围的单引号)并尝试将其传递给 powershell 脚本。我现在收到以下错误:
svn: E020024: Error resolving case of 'https:\some_repo.abc.com\svn\dir with space\util'
另一件需要注意的事情是,如果我将 URL 中的反斜杠更改为正斜杠,它在命令行上 fine 有效。从 Puppet 调用仍然无效。
发布根据@AnsgarWiechers 的建议为我制定的最终配置。
[tom@pe-server] cat repo_checkout.pp
define infra::svn::repo_checkout ($svn_url_params) {
$svn_url = $svn_url_params[svn_url]
...
...
util::executeps { 'Checking out repo':
pspath => $repo_checkout_ps,
argument => "\"$svn_url\"",
}
}
[tom@pe-server] cat repo_checkout.ps1
$svn_url = $args[0]
Set-Location C:\build
svn co --username user --password xxx --non-interactive "$svn_url"
[tom@pe-server] cat params.pp
$repo_checkout_ps = 'c:/scripts/infra/repo_checkout.ps1',
[tom@pe-server] cat site.pp
$svn_url_ad = {
svn_url => 'https://some_repo.abc.com/svn/dir with space/util',
}
infra::svn::repo_checkout { "Checking out code in C:\build":
svn_url_params => $svn_url_ad
}
非常感谢@AnsgarWiechers! :)
注:
- 在 site.pp 中:在指定
svn_url
时使用正斜杠 - 在 repo_checkout.ps1 中:将
'$svn_url'
更改为"$svn_url"
- 在 repo_checkout.pp 中:将
argument
中的双嵌套('
和"
)引用更改为单引用("
) 嵌套,即从"\'\"$svn_url\"\'"
到"\"$svn_url\""
(/)