Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

How to use Lists in iRule

I'm trying to do a redirect to a specific node for a specific set of sites using our F5. I can do a single site easily using the following irule:

when HTTP_REQUEST {
    if { [string tolower [HTTP::host]] ends_with "site1.mysite.com" } {
        node 10.1.1.31
    }
}

And for a single site this is fine. My problem is I need to do this for about ~130 sites, and want to manage a list of sites that is called in the irule as these sites that are being redirected might be changed over time.

I created a list in my partition under System --> File management --> iFile List called MyList that was imported from MyList.txt on my local machine.

I then went to Local Traffic --> iRules --> Data Group List and created MyList as a string. I tried to add it as an address list, but got the following error:

The requested class IP item (/LB_Stage_Web/MyList 10.XXX.XXX.XXX%1 255.255.255.255) already exists in partition LB_Stage_Web.

So I'm just really wondering how I can use the list functionality to get this to work.

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Better solution is to configure local traffic policies!

With local traffic policy, create a new policy with one rule

  • name redirect
  • condition :
    • http- host host is in
      • site1.mysite.com
      • site2.mysite.com
      • site3.mysite.com
  • action :
    • forward node 1.2.3.4
0
Comments on this Answer
Comment made 2 months ago by bjtstarks 1

Oh my gosh! I LOVE the traffic policy. Didn't know about this before, but holy crap! It works so beautifully.

One thing I did change is I didn't just do

  • name redirect
  • condition :

    • http- host host is in

      • site1.mysite.com
      • site2.mysite.com
      • site3.mysite.com
    • action :

      • forward node 1.2.3.4

But instead I did:

  • name redirect
  • condition :

    • http-host host is in datagroup

      • mydatagroup
    • action :

      • forward node 1.2.3.4

I then created my datagroup with:

  • site1.mysite.com
  • site2.mysite.com
  • site3.mysite.com
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Check this out:

https://devcentral.f5.com/articles/intermediate-irules-data-groups-20430

You need to take the contents of the file you imported and set it to the key/values in the datagroup.

ltm data-group internal my_datagroup {
records {
    site1.mysite.com {
        data 10.1.1.31
    }
    site2.mysite.com {
        data 10.1.1.32
    }
    ...
    site130.mysite.com {
        data 10.1.1.130
    }
}
type string
}

Then you can do a single statement like:

if { [class match [string tolower [HTTP::host]] equals "my_datagroup" ] } {
  node [class match -value [string tolower [HTTP::host]] equals "my_datagroup"
}

You could add the records in via the GUI or tmsh, or create the file like that and merge it in, or even add it to the bigip.conf and just to a tmsh load sys config.

0
Comments on this Answer
Comment made 2 months ago by bjtstarks 1

This looks like what I was looking for. Thanks! I'll give it a try and let you know how it goes.

0