1

我在 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 文件中?我需要逃避%'s吗?

4

1 回答 1

1

简短的回答,是的。

在 Hiera 中,有插值标记

插值标记看起来像%{variable}%{function("input")}。也就是说,它们包括:

  • 百分号 (%)
  • 左大括号 ({)

之一:

  • 变量名
  • 查找函数及其输入(Hiera 1.3 及更高版本)
  • 闭合花括号

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

这意味着您%{GLOBAL}与插值标记完全匹配。在您的最终输出中,Puppet 显示该变量没有值,GLOBAL并且输出空白。

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

于 2016-01-22T17:15:34.287 回答