Forum: CFEngine Help
Subject: Re: Find which nic(s) match with iprange?
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,24908,24914#msg-24914

Hi Nick,

I was going to reply with what's below, but then I realized that you are 
correct - iprange() doesn't allow you to specify which IP address to check, it 
just checks all addresses of the current host. Maybe open a ticket?

--Diego

My original response:

Maybe something like this would work: 
http://cf-learn.info/code/ch04/edit_inittab_tso.cf.html (example from my book)

bundle agent disable_tso_flag
{
  vars:
      "ipregex" string => "192\.168\..*"; 
      "nics"    slist  => getindices("sys.ipv4");

  classes:
      "isgreen_$(nics)" expression => regcmp("$(ipregex)", 
"$(sys.ipv4[$(nics)])"); 

  files: 
      "$(configfiles.files)"
        handle => "inittab_add_ethtool",
        comment => "Ensure ethtool is run on startup to disable the TSO flag",
        create => "false",
        edit_defaults => edit_backup,
        edit_line => replace_or_add("tso:3:.*", 
                                    "tso:3:once:/usr/sbin/ethtool -K $(nics) 
tso off"),
        ifvarclass => "isgreen_$(nics)";
}


But using iprange() instead of regcmp() for setting the isgreen_$(nics)" class?

The class isgreen_ will be defined if that NIC's IP address is in the given 
range, which you can then use to decide what to do.

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to