Puppet是否在我的YAML数据中评估变量?

时间:2016-01-07 23:03:09

标签: yaml wsgi hiera puppet-enterprise

我在我的hiera数据中的yaml文件中有这个:

wsgi_keystone_conf_contents: |
 Listen 5000 
 Listen 35357

 <VirtualHost *:5000>
     WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
     WSGIProcessGroup keystone-public
     WSGIScriptAlias / /var/www/cgi-bin/keystone/main
     WSGIApplicationGroup %{GLOBAL}
     WSGIPassAuthorization On
     LogLevel info 
     ErrorLogFormat "%{cu}t %M"
     ErrorLog /var/log/httpd/keystone-error.log
     CustomLog /var/log/httpd/keystone-access.log combined
 </VirtualHost>

 <VirtualHost *:35357>
     WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
     WSGIProcessGroup keystone-admin
     WSGIScriptAlias / /var/www/cgi-bin/keystone/admin
     WSGIApplicationGroup %{GLOBAL}
     WSGIPassAuthorization On
     LogLevel info 
     ErrorLogFormat "%{cu}t %M"
     ErrorLog /var/log/httpd/keystone-error.log
     CustomLog /var/log/httpd/keystone-access.log combined
 </VirtualHost>

我尝试在我的木偶清单中创建一个wsgi-keystone.conf文件,如下所示:

file { '/etc/httpd/conf.d/wsgi-keystone.conf':
    ensure   => present,
    content  => $wsgi_keystone_conf_contents,
}

但这导致文件看起来像这样......

Listen 5000
Listen 35357

<VirtualHost *:5000>
    WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=
    WSGIProcessGroup keystone-public
    WSGIScriptAlias / /var/www/cgi-bin/keystone/main
    WSGIApplicationGroup
    WSGIPassAuthorization On
    LogLevel info
    ErrorLogFormat "t %M"
    ErrorLog /var/log/httpd/keystone-error.log
    CustomLog /var/log/httpd/keystone-access.log combined
</VirtualHost>

<VirtualHost *:35357>
    WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=
    WSGIProcessGroup keystone-admin
    WSGIScriptAlias / /var/www/cgi-bin/keystone/admin
    WSGIApplicationGroup
    WSGIPassAuthorization On
    LogLevel info
    ErrorLogFormat "t %M"
    ErrorLog /var/log/httpd/keystone-error.log
    CustomLog /var/log/httpd/keystone-access.log combined
</VirtualHost>

上述文件有语法错误,httpd不会重启。我怎么把数据放在我的YAML文件中?我是否需要逃避%

1 个答案:

答案 0 :(得分:1)

简短的回答,是的。

在Hiera,有interpolation tokens

  

插值令牌看起来像unset()%{variable}。也就是说,它们包括:

     
      
  • 百分号(%)
  •   
  • 开口花括号({)
  •   
     

其中一个:

     
    
        
  • 变量名称
  •     
  • 查找功能及其输入(Hiera 1.3及更高版本)
  •     
  
     
      
  • 结束大括号
  •   
     

如果配置文件中的任何设置或数据源中的值包含插值标记,Hiera将使用它在运行时引用的值替换标记。

这意味着您的%{function("input")}与插值令牌完全匹配。在你的最终输出中,Puppet显示变量%{GLOBAL}没有值,它输出空白。

escaping Hiera data上有一个关于SO的帖子,但我不认为这通常是你想要做的。最好的做法是编写一个erb模板,然后简单地将值传递给你想要放入的模板而不是配置文件的全部内容。