Forum Discussion

Wally_Steadman_'s avatar
Wally_Steadman_
Icon for Nimbostratus rankNimbostratus
Jun 25, 2012

create IRule in tmsh

Greetings all,

 

I am trying to create an IRule from the command line in tmsh and running into errors that I am not sure how to correct.

 

 

I know there are other tools out there such as IControl that can be used but at this time we are doing configurations from the tmsh shell and I will investigate the other options later.

 

 

Using LTM Version 11.2 and trying to create the IRule I do the following from the tmsh prompt:

 

 

create ltm rule /Common/my_rule_rule { when HTTP_REQUEST { if { [class match [HTTP::uri] contains this_uri] } { pool my_test_pool_1 } else { pool my_test_pool_2 }}}

 

 

I get the following error:

 

Syntax Error: Unexpected {

 

 

I have tried removing some of the { but still having an issue.

 

 

I noticed that if I typed create ltm rule /Common/my_rule_rule that it takes me into an editor mode to apparently apply the rule. Is there a way to create the rule without having to go into the editor mode?

 

 

 

6 Replies

  • Hi Wally,

     

     

    As far as I can tell you need to use editor mode to create a new iRule. I'll see if there is another option with tmsh.

     

     

    Aaron
  • This compiles for me just fine

     

     

    when HTTP_REQUEST {if {[class match [HTTP::uri] contains this_uri]}{pool my_test_pool_1} else {pool my_test_pool_2}}

     

     

     

    You might try removing any extra spaces that you can. Do you have to have the bracket before when and the third bracket at the end? Haven't written an iRule in TMSH. The iRule Editor will become your best friend :)
  • Hey Hoolio,

     

     

    I tried in TMSH 10.2.4 but the operator "rule" isn't valid past LTM. I can do "create ltm node" and a few others but rule isn't an option. Though it does show up when using the show command for statistics.... Guessing rule was added in TMOS 11?

     

  • Hey Naladar, the 'tmsh create ltm rule rule_name' option was added in 11.0. In 10.x you could do the same using 'tmsh edit ltm rule rule_name'.

     

     

    Wally, can you open a case with F5 Support requesting the ability to create a single or multi-line iRule without using editor mode like we could with bigpipe (b rule test_rule '{ ... }')? Requests from customers can carry more weight than from F5ers :) If you do so, can you reply back with the RFE ID you receive so others can reference it?

     

     

    Thanks, Aaron
  • How I have resolved the issue is by using the “Load sys config from-terminal merge” command and pasting the config in and then committing with CTRL-D

     

     

    This works great. Kind of like the bpsh commands. This is the route I am going to take with my documentation for our analysts. What I like about it is that if your config is messed up, it tells you without committing.

     

     

    When I get some free time, I will open a case to see if the rules can created with single line and multi line without using the editor.

     

     

    Wally
  • MVA's avatar
    MVA
    Icon for Nimbostratus rankNimbostratus

    Wally, this loads for me on 11.4.1 HF3

     

    tmsh create ltm rule /Common/my_rule_rule when HTTP_REQUEST { if { [class match [HTTP::uri] contains this_uri] } { pool my_test_pool_1 } else { pool my_test_pool_2 }}

     

    Removed the "{" between rule name and when statement and corresponding "}" at the end.

     

    Couple other notes: - Double quotes require backslash delimiter, i.e., if { [HTTP::host] starts_with \"myhost\"} - Linefeeds require backslash delimiter, if using LF for clarity, i.e., tmsh create /ltm rule test_rule \ when HTTP_REQUEST {\ if { [HTTP::host] starts_with \"myhost\" } } else {\ discard\ }\ }

     

    We use scripts for change control and create (most)everything at the console. Hope this helps.