Forum Discussion

bjorg235's avatar
bjorg235
Icon for Altocumulus rankAltocumulus
Aug 22, 2019

TMSH command to add irule

Hello Team

 

I need to add syslog irule to all the VIPs in f5. Already all VIps has more than 2-3 irules each. If I execute modify ltm virtual <> rules { syslog_rule } it is repalcing existing rules. Is there any way via tmsh command I can simply append new irule .Please help

 

 

 

  • You don't need to write a shell script, you can use the 'edit' feature in tmsh.

    For example, if you wanted to add an iRule to all of your virtual servers you could do the following

    tmsh edit ltm virtual all

    This bring up the vim editor, so you can use find and replace to add a new iRule to all your virtual servers with one line

    :%s/rules {/rules {\r\tnew-irule/g
  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    You can run the "list" function to get the list of the existing irules attached to a VS, and then add the new irule to the list and then attach to the VS.

    • bjorg235's avatar
      bjorg235
      Icon for Altocumulus rankAltocumulus

      HI JG,

      Thanks for your reply

      Yes you are right for 1 VIP. But I need to add for 300 VIPs.

       

      I am planning for a shell script

  • You don't need to write a shell script, you can use the 'edit' feature in tmsh.

    For example, if you wanted to add an iRule to all of your virtual servers you could do the following

    tmsh edit ltm virtual all

    This bring up the vim editor, so you can use find and replace to add a new iRule to all your virtual servers with one line

    :%s/rules {/rules {\r\tnew-irule/g
    • bjorg235's avatar
      bjorg235
      Icon for Altocumulus rankAltocumulus

      Thank you so much ..It worked..could you help to place the irule in the last. With the above I am getting irrule in the first

      • Lee_Sutcliffe's avatar
        Lee_Sutcliffe
        Icon for Nacreous rankNacreous

        If I were you, I wouldn't rely on ordering your iRules on the virtual server.

        Instead, use iRule priority so they are executed in the order you require eg

        rule my-first-irule {
            when HTTP_REQUEST priority 10  {
                #this will run first
            }
        }
        rule my-second-irule {
            when HTTP_REQUEST priority 20  {
                #this will run second
            }
        }

        https://clouddocs.f5.com/api/irules/priority.html

    • Angryman808's avatar
      Angryman808
      Icon for Nimbostratus rankNimbostratus

      This is genius, would you be able to write similar code to remove an iRule from all virtual servers as well?