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

Filter by:
  • Solution
  • Technology

create irule with variable in iApp

Hi Devcentral!

I've a questions:

I'm modifying an iApp in order to create an irule to assign to the vs.

the assignment is here { [iapp_conf create ltm virtual ${app}_vs \ destination [iapp_destination $::pool__addr $::pool__port] \ mask $mask \ $vs_params \ ip-protocol tcp \ mirror $mirror_action \ profiles replace-all-with { $tcp_profiles http } \ rules { iwf_test_irulebal iwf_$irulelog }] }

the irules are very simple

the first irule is with no variables

tmsh::create ltm rule iwf_$irulelog { 

    log local0. "No variables" 


the second irule need to balance on the pool created with the iapp, so i need to write it with variable statement and not with string

tmsh::create ltm rule iwf_test_irulebal {


if { [HTTP::uri] starts_with "/portal${app}_pool" } {
    use pool ${app}_pool }
else {

i've tried with \before the { but seems not works. also with ::global variable but not works.

In a classic BIG-IP environment without iapp the use of variable in irule works. how can i use the variable in an irule created with an iapp?

thanks in advance

Rate this Question

Answers to this Question


iApps are fussy with brackets, braces, and quotes, and need a lot of escape characters, especially when creating an iRule. As a result, I like to set a variable to the iRule code string (with all the escape characters) and then refer to the variable on the tmsh::create command, rather than try to do it all on one command. Makes maintenance a bit easier, too:

set MyRule "
   if \{ \[HTTP::uri\] starts_with \"/portal${app}_pool\" \} \{
      pool ${app}_pool
   \} else \{
tmsh::create "/ltm rule ${app}_MyRule $MyRule"

Notice the braces in ${app} are not escaped so that the iApp processor will perform variable substitution when the application service is deployed. But all the braces, brackets, and quotes that need to be present in the finished iRule must be escaped.

Comments on this Answer
Comment made 06-Nov-2017 by jojo83 69

Hi crodriguez,

I tried to deploy by following your suggestion and it works.

in the meantime I had tried this way:

set :: iapp_sn $ tmsh :: app_name set :: pool_irule $ {:: iapp_sn} _pool

set infile1 [open "/var/tmp/irule.tmp" "w" "0644"] puts $ infile1 "ltm rule /Common/$::iapp_sn.app/irule$::iapp_sn \ {" puts $ infile1 "app-service $ :: iapp_sn" puts $ infile1 "when HTTP_REQUEST \ {" puts $ infile1 "if \ {\ [HTTP :: uri ] starts_with \" / portal $ :: iapp_sn \ "} \ {" puts $ infile1 "use pool $ :: pool_irule }" puts $ infile1 "elseif \ {\ [HTTP :: uri ] starts_with \" / script $ :: iapp_sn \ "} \ {" puts $ infile1 "use pool $ :: pool_irule }" puts $ infile1 "else \ {" puts $ infile1 "TCP :: close" puts $ infile1 "}" puts $ infile1 "}" puts $ infile1 "}" close $ infile1

tmsh :: load sys config merge check file /var/tmp/irule.tmp

file delete "/var/tmp/irule.tmp"

set irulevs "/Common/$::iapp_sn.app/irule$::iapp_sn"

and it works. but I do not like the idea of ​​creating a file and then destroying it, too, because you might be faced with permission issues.

so I prefer to do as you suggest

thank you so much regards