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 called when)

Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Change The Font Size Of Visual Studio Solution Explorer