我有一个运行多个站点的 Ansible 配置的服务器。
我的 Ansible 任务大致如下:
- name: site nginx config
template: src="nginx-site.conf.j2" dest=/etc/nginx/conf.d/{{item.name}}.conf
owner=root group=root mode=0444
with_items: sites
notify: restart nginx
- name: nginx conf
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
owner=root group=root mode=0444
notify: restart nginx
Run Code Online (Sandbox Code Playgroud)
我想使用validateAnsible 模板模块的参数来调用nginx -t并确保我的新配置在语法上有效。它适用于主要的 nginx.conf:
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
owner=root group=root mode=0444
validate="/usr/sbin/nginx -c %s -t"
Run Code Online (Sandbox Code Playgroud)
但它似乎没有对特定于站点的配置文件进行更改。放置validate特定于站点的模板不起作用,因为它们需要包含在http指令中才能有效。
我可以做些什么来检查这些特定于站点的文件的有效性?