0

I need to exclude certain minions marked with either of these custom added grains from getting a software installation Salt state:

exclude:
  - applications
  - application_xyz

The following syntax that works, and prevents any minions with the "applications" grain from installing anything:

{% if not "applications" in grains.get('exclude', []) %}

But now I need to get more specific, and that's where I thought using "or" logic made sense. So far I've tried the following, neither of which work:

{% if not "applications" or "application_xyz" in grains.get('exclude', []) %}

{% if not "applications" in grains.get('exclude', []) or not "application_xyz" in grains.get('exclude', [])  %}

I used How to use logic operators in jinja template on salt-stack (AND, OR) as some reference, so I feel that I may be on the right track.

Any help or advice is hugely appreciated!

  • 1
    To my eyes, the first approach is syntactically incorrect. The second looks syntactically correct, but has error in logic. One of De Morgan’s laws states: `not (A or B) = not A and not B`. For reference, see https://en.wikipedia.org/wiki/De_Morgan%27s_laws – Lesiak Dec 01 '20 at 19:51

1 Answers1

0

For anyone who runs into the same situation I've found that the following works perfectly.

{% if not ['applications','application_xyz'] | intersect(grains.get('exclude', [])) %}

Here, any minions with either applications, or application_xyz will be passed over.