Ansible - 如何匹配具有特定布尔变量的主机?

Ansible - How to match against hosts with certain bool variable?

小语境:

我清单中的某些主机需要 nginx 访问限制。为此,我实现了一个 bool restrict_access: yes,现在我需要重新 运行 我的 nginx 设置角色。

有没有办法匹配 将此标志设置为 true 的主机?谢谢!

您可以在任务级别实现它

例如:

# roles/webserver/tasks/main.yml  
- import_tasks: configure-nginx.yml
  when: restrict_access

- import_tasks: do-not-configure-nginx.yml
  when: not restrict_access