只有当主机属于一个或多个组时,运行任务的理智方式是什么?
目前,我在相关组中使用布尔值,例如:
[db_servers:vars]
copy_connection_string=true
-
name: Copy db connection string file
synchronize: src= ... (truncated for clarity)
when: copy_connection_string is defined
when
子句中检查当前主机是否属于db_servers
组的正确条件是什么?
答案 0 :(得分:14)
Ansible包含special or magic variables - one of the most common is group_names
which is a list (array) of all the groups the current host is in.
- name: Copy db connection string file
synchronize:.........
when: "'db_servers' in group_names"
只有当主持人是db_servers
群组的成员时,才会运行上述Ansible任务。