salt icon indicating copy to clipboard operation
salt copied to clipboard

General question about targeting partial IP address

Open evenyougreg opened this issue 7 years ago • 2 comments

I am trying to use some jinja logic like so...

{% if grains["ipv4"] == "10.171.*" %}

do stuff

{% endif %}

but this does not work, so how can I go about achieving this?

Thanks,

Greg UWHealth

evenyougreg avatar Jul 24 '19 13:07 evenyougreg

@LaughHammers The first thing that comes to mind is this:

{% if grains["ipv4"].startswith("10.171") %}

do stuff

{% endif %}

If this doesn't work then you'll probably want to look into using a custom module. An example of this can be found here: https://groups.google.com/forum/#!topic/salt-users/EUbnCGlroAA

dwoz avatar Jul 30 '19 04:07 dwoz

@dwoz This is what ended up working for me.

{% if salt.network.ip_in_subnet( salt'network.ip_addrs' , '10.171.0.0/16' ) %}

evenyougreg avatar Aug 07 '19 14:08 evenyougreg