我有两个在 saltstack 下管理的 httpd 服务器的仆从。VirtualHost基于端口需要为它们单独配置。所以/etc/httpd/conf.d/httpd-vhost.conf是这样看的:
httpd:
pkg.installed: []
service.running:
- require:
- pkg: httpd
- watch:
- file: /etc/httpd/conf.d/httpd-vhosts.conf
/etc/httpd/conf.d/httpd-vhosts.conf:
file.managed:
- source: salt://webserver/httpd-vhosts.conf
Run Code Online (Sandbox Code Playgroud)
问题是这两个 Minion 有自己的服务器名称,httpd-vhost.conf应该像ServerName www.example1.com和一样不同www.example2.com。Saltstackgrains模块只适用于 .sls 文件而不是托管文件。那么有什么建议可以让它发挥作用吗?
只需添加- template: jinja到您的file.managed,您就可以在配置文件中使用谷物。
/etc/httpd/conf.d/httpd-vhosts.conf:
file.managed:
- source: salt://webserver/httpd-vhosts.conf
- template: jinja
Run Code Online (Sandbox Code Playgroud)
您可以在源文件中使用谷物,如下所示:
{% if grains['id'] == 'dev' -%}
ServerName dev.example.com
{% else %}
ServerName example.com
{% endif -%}
Run Code Online (Sandbox Code Playgroud)
正是这个功能在 SaltStack 上卖给了我。
| 归档时间: |
|
| 查看次数: |
3160 次 |
| 最近记录: |