我在层次结构数据的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文件中?我需要逃离%
吗?
简短回答,是。
在Hiera中,有插值标记:
插值标记看起来像
%{variable}
或%{function("input")}
。也就是说,它们包括:
- 百分号(%)
- 左大括号({)
其中之一:
- 变量名
- 查找函数及其输入(Hiera 1.3及更高版本)
- 闭合大括号
如果配置文件中的任何设置或数据源中的值包含插值令牌,Hiera将用运行时引用的值替换该令牌。
这意味着您的%{GLOBAL}
与插值令牌完全匹配。在您的最终输出中,Puppet显示它没有变量GLOBAL
的值,并且它输出空白。
SO上有一个关于转义Hiera数据的线程,但我认为这通常不是你想要做的。最佳做法是编写一个erb模板,只需将值传递给你想要放入的模板,而不是配置文件的全部内容。