无法使用Puppet

时间:2017-03-23 09:27:53

标签: powershell svn puppet powershell-v5.0

我正在尝试从SVN repo中检出代码,我接受该URL作为参数。我引用了如下所示的URL,因为它包含空格。我还通过重定向文件中的$svn_url来检查参数(如下所示)。如果我从文件中选择URL并将命令行中的 传递给给定的脚本,它可以正常工作但不知何故从Puppet调用时,它无法正常工作。

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 < / em>如果我从我重定向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调用仍然无法正常工作。

1 个答案:

答案 0 :(得分:0)

根据@ AnsgarWiechers&#39;发布针对我的最终配置。建议。

[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 中:指定(/)
  • 时使用了forwardslashes svn_url
  • repo_checkout.ps1 中:将'$svn_url'更改为"$svn_url"
  • repo_checkout.pp 中:将'中引用的双嵌套("argument)更改为单个(")嵌套,即,从"\'\"$svn_url\"\'""\"$svn_url\""