【问题标题】:How to have chef template have a "["?如何让厨师模板有一个“[”?
【发布时间】:2014-10-10 17:06:11
【问题描述】:

我想要厨师模板来生成 Django settings.py 文件。但看起来 settings.py 中的列表对象总是让厨师陷入困境:

这是模板的源代码:

 91: # DNS configurations
 92: DEFAULT_NAMESERVERS = [ 
 93: <% @nameservers.each do |ns| %>
 94: '<%=#{ns}%>',
 95: <% end %>
 96: ] 
 97: 

我总是收到以下错误消息:

 * template[/var/www/pdnsrestserver/pdnsrestserver/settings.py] action create

    ================================================================================
    Error executing action `create` on resource 'template[/var/www/pdnsrestserver/pdnsrestserver/settings.py]'
    ================================================================================

    Chef::Mixin::Template::TemplateError
    ------------------------------------
    **(erubis):96: syntax error, unexpected ']', expecting ')'**
     _buf << '] 
               ^
    (erubis):172: syntax error, unexpected '}', expecting ')'

【问题讨论】:

    标签: templates chef-infra


    【解决方案1】:

    我确实认为您缺少空格并且在带引号的字符串之外有一个插值代码

    我认为这可行:

     91: # DNS configurations
     92: DEFAULT_NAMESERVERS = [ 
     93: <% @nameservers.each do |ns| %>
     94: '<%= ns %>',
     95: <% end %>
     96: ] 
     97: 
    

    未经测试的代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-29
      • 2015-03-20
      • 1970-01-01
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      • 2016-10-27
      • 1970-01-01
      相关资源
      最近更新 更多