arenginsm na
arenginsm na

Reputation: 171

Conditional text in variable in ansible

H I want to build a warning message with ansible that is stored in a variable:

I have {{total}} and {{wanted}} and I want to store that in a {{outcome}} variable :

I need something like :

if ({{total}} < {{wanted}}): {{outcome}}= "you need to much"
else if ({{total}} = {{wanted}}): {{outcome}}= "Could work out"
else: {{outcome}}= "Ok"

How can I get this to work?

Thanks for any ideas... this is driving me crazy....

Upvotes: 2

Views: 334

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 68034

The task below does the job

- set_fact:
    outcome: |
      {% if total|int < wanted|int %}
      You need to much
      {% elif total|int == wanted|int %}
      Could work out
      {% else %}
      Ok
      {% endif %}

Upvotes: 2

Related Questions