检查字符串是否等于和 Ansible 中的三元运算符 [英] Check if strings are equals and ternary operator in Ansible

查看:17
本文介绍了检查字符串是否等于和 Ansible 中的三元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的剧本中,我有这个:

In my playbook, I have this:

#More things
- include: deploy_new.yml
  vars:
    service_type: "{{ expose_service == 'true' | ternary('NodePort', 'ClusterIP') }}"
    when: service_up|failed

expose_service 为 true 时,我希望将 service_type 设置为 NodePort,否则设置为 ClusterIP.

When expose_service is true, I want service_type to be set to NodePort, and ClusterIP otherwise.

但是,service_type 在所有情况下都设置为 False.

However, service_type is set to False in all cases.

我做错了什么?

推荐答案

已解决!

service_type: "{{ 'NodePort' if expose_service == 'true' else 'ClusterIP' }}"

这篇关于检查字符串是否等于和 Ansible 中的三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆