【问题标题】:Chef throwing error in Execute resource厨师在执行资源中抛出错误
【发布时间】:2014-12-05 00:59:54
【问题描述】:

我正在编写一个非常基本的方法来将数据从一个文件夹复制到另一个文件夹。我写了以下代码:

执行“file_sharing”做

命令 "复制 "X:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tomcat-6.0.32\apache-tomcat-6.0.32\webapps"; /Y;"

结束

当我转到我的节点并尝试执行此命令时,它运行得非常好。但是,如果我尝试通过 Chef 运行此食谱,则会引发错误。附上错误截图。请查看并提出解决方案。![错误

command "copy "X:\B2BPortal-0.0.1-SNAPSHOT.wa...
                ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: no .<digit> floating literal anymore; put 0 before dot
...ommand "copy "X:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-to...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tINTEGER
...mmand "copy "X:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tom...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tSTRING_BEG, expecting keyword_end
...:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tomcat-6.0.32\apa...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tCONSTANT, expecting keyword_end
...2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tomcat-6.0.32\apache...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: no .<digit> floating literal anymore; put 0 before dot
...HOT.war" "C:\apache-tomcat-6.0.32\apache-tomcat-6.0.32\webap...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tINTEGER
...T.war" "C:\apache-tomcat-6.0.32\apache-tomcat-6.0.32\webapps...
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: no .<digit> floating literal anymore; put 0 before dot
...omcat-6.0.32\apache-tomcat-6.0.32\webapps"; /Y;"
...                               ^
c:/chef/cache/cookbooks/file_sharing/recipes/default.rb:11: syntax error, unexpected tINTEGER
...cat-6.0.32\apache-tomcat-6.0.32\webapps"; /Y;"

]1

【问题讨论】:

    标签: chef-infra


    【解决方案1】:

    在 Ruby 中,\(反斜杠)用于字符串转义序列,例如 \n\t。您可以使用\\ 或单引号',因为它们不会处理反斜杠转义。

    【讨论】:

      【解决方案2】:

      您必须转义命令字符串中的双引号和反斜杠,或者将其包裹在单引号中。由于您没有在那里进行任何变量插值,我建议使用后者。

      试试这个:

      execute "file_sharing" do
        command 'copy "X:\B2BPortal-0.0.1-SNAPSHOT.war" "C:\apache-tomcat-6.0.32\apache-tomcat-6.0.32\webapps" /Y;'
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-11
        • 1970-01-01
        • 2016-12-30
        • 2013-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多