下面是我在 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 (变量预分配在变量文件中)
我怎样才能做到这一点?
尝试这个 :
client_dc: "{% if 'jira-app' in hostname %}jira{% elif 'jira-next' in hostname %}jira-next{% else %}{{ hostenv }}{% endif %}"
Run Code Online (Sandbox Code Playgroud)
在 Ansible Jinja 中使用 else if 的另一个示例
- name: Set Service status
set_fact:
service_status: "{{ 'Not Installed' if status is not defined else ( 'Running' if status == 200 else 'Not Running' ) }}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17787 次 |
| 最近记录: |