下面是我在 ansible 中的元文件的一部分。
---
dependencies:
- { role: nomad-agent,
nomad_agent_type: client,
client_dc: "{{ 'jira' if 'jira-app' in host_name else host_env }}",
nomad_servers: ["{{ nomad1_ip }}","{{ nomad2_ip }}","{{ nomad3_ip }}"],
tags: "nomad-agent"
}
Run Code Online (Sandbox Code Playgroud)
在 client_dc 选项中,我需要以这样的方式添加 elif,如果在主机名中找到“jira-next”,client_dc 将被分配给“jira-next”。因此,如果在主机名中找到 'jira-app',则 client_dc: jira elif 'jira-next-app' 在主机名中找到,client_dc: jira-next 否则 client_dc: host_name (变量预分配在变量文件中)
我怎样才能做到这一点?