Check If Strings Are Equals And Ternary Operator In Ansible
Answer :
Solved!
service_type: "{{ 'NodePort' if expose_service == 'true' else 'ClusterIP' }}"
In your example you are applying the ternary filter to the 'true'
string. Effectively you are comparing the value of expose_service
with the string 'NodePort'
and always get false
in result.
You need to enclose the equality operator-clause in parentheses:
- include: deploy_new.yml vars: service_type: "{{ (expose_service == true) | ternary('NodePort', 'ClusterIP') }}" when: service_up|failed
The other other two points addressed in this answer:
- you use the string
'true'
instead of Boolean when
directive is on wrong indentation level (you effectively pass the variable calledwhen
)
Comments
Post a Comment