Liquidmonkey
Liquidmonkey

Reputation: 21

Compare two grain values inside state.sls using jinja expressions

I am creating a state which will trigger some module if both of the grains are not matching. I have tried several options, but no luck.

Based on comparison, False will trigger my module and that module will change GRAIN_B value to match with GRAIN_A. So during every highstate my module will not get triggered, unless there is a change in GRAIN_A.

Any suggestions please.

I have tried several jinja expressions.

{% if grains['GRAIN_A'] not in grains.get('GRAIN_B','None') %}
{% set GRAIN_B = grains.get('GRAIN_B','None') %}
{% if grains['GRAIN_A'] != {{ GRAIN_B }} %}```

```{% if grains['GRAIN_A'] not in grains.get('GRAIN_B','None') %}
MY_MODULE:
  module.run:
   - func: MYMODULE.FUNCTION_A
{% endif %}```

Upvotes: 1

Views: 633

Answers (1)

Liquidmonkey
Liquidmonkey

Reputation: 21

Issue fixed, there is a \n character in my GRAIN_A output, which makes the evaluation condition fails.

This condition works already.

{% if grains['GRAIN_A'] not in grains.get('GRAIN_B','None') %} MY_MODULE: module.run: - func: MYMODULE.FUNCTION_A {% endif %}

Upvotes: 1

Related Questions