{"id":800,"date":"2013-09-01T00:00:00","date_gmt":"2013-09-01T00:00:00","guid":{"rendered":"https:\/\/fir3netwp.gmsrrpobkbd.com\/2013\/09\/01\/f5-ltm-irule-variables\/"},"modified":"2021-07-24T17:20:34","modified_gmt":"2021-07-24T17:20:34","slug":"f5-ltm-irule-variables","status":"publish","type":"post","link":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html","title":{"rendered":"F5 LTM – iRule Variables"},"content":{"rendered":"

The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article we will look at the variables. There are 2 main types of variables, local and global.<\/p>\n

Local<\/strong><\/h2>\n

Local variables represent data within your local namespace, and are assigned the same scope as the iRule that created it. This also means that local variables are shared across all iRules for a Virtual Server. In addition to this local variables are also session based.<\/p>\n

Below shows you how you would assign, output and unassign a local variable.<\/p>\n

set uri “picture.jpg”     <- assign var
log local0. “uri is $uri” <- output var
unset uri                 <- unassign var<\/p>\n

Global<\/strong><\/h2>\n

Unlike local variables, global variables exist outside of the local namespace, meaning that they aren’t bound to a single session but instead a TMM instance. An example of when a global variable may be required would be the assignment of an IP address to a variable that you would want available to every session across the F5 system.<\/p>\n

Unfortunately global variables are not shared across TMM instances and are only available globally within the local TMM instances. Because of this using a global variable within an iRule demotes CMP (Clustered Multi-Processing) from the associated virtual server.<\/p>\n

set ::uri “picture.jpg”     <- assign var
log local0. “uri is $::uri” <- output var
unset ::uri                 <- unassign var<\/p>\n

Static Global<\/strong><\/h4>\n

Static global variables overcome the CMP demotion problem by sharing the data across each TMM instance. However as the name suggests the variable is static, and is only defined each time the iRule is initialized. <\/p>\n

when RULE_INIT {
  set static::debug 0
}<\/p>\n

when HTTP_REQUEST {
  if { $static::debug } {
    log local0. “debug equals $static::debug”
}<\/p>\n

References
<\/strong><\/h2>\n

https:\/\/devcentral.f5.com\/tech-tips\/articles\/irules-101-03-variables<\/a>
https:\/\/devcentral.f5.com\/tech-tips\/articles\/-the101-irules-101-variables<\/a>
http:\/\/support.f5.com\/kb\/en-us\/solutions\/public\/13000\/000\/sol13033.html<\/a> 
https:\/\/devcentral.f5.com\/wiki\/irules.static.ashx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article we will look at the variables. There are 2 main types of variables, local and global. Local Local variables represent data within your local namespace, and are assigned the … Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"yoast_head":"\nF5 LTM - iRule Variables - Fir3net<\/title>\n<meta name=\"description\" content=\"The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"F5 LTM - iRule Variables - Fir3net\" \/>\n<meta property=\"og:description\" content=\"The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html\" \/>\n<meta property=\"og:site_name\" content=\"Fir3net\" \/>\n<meta property=\"article:published_time\" content=\"2013-09-01T00:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-24T17:20:34+00:00\" \/>\n<meta name=\"author\" content=\"Rick Donato\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rick Donato\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html\"},\"author\":{\"name\":\"Rick Donato\",\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/person\/ab35009601b7687ee1c5310be6038037\"},\"headline\":\"F5 LTM – iRule Variables\",\"datePublished\":\"2013-09-01T00:00:00+00:00\",\"dateModified\":\"2021-07-24T17:20:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html\"},\"wordCount\":384,\"publisher\":{\"@id\":\"https:\/\/www.fir3net.com\/#organization\"},\"articleSection\":[\"F5 Loadbalancers\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html\",\"url\":\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html\",\"name\":\"F5 LTM - iRule Variables - Fir3net\",\"isPartOf\":{\"@id\":\"https:\/\/www.fir3net.com\/#website\"},\"datePublished\":\"2013-09-01T00:00:00+00:00\",\"dateModified\":\"2021-07-24T17:20:34+00:00\",\"description\":\"The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article\",\"breadcrumb\":{\"@id\":\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.fir3net.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Networking\",\"item\":\"https:\/\/www.fir3net.com\/networking\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Loadbalancers\",\"item\":\"https:\/\/www.fir3net.com\/networking\/loadbalancers\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"F5 Loadbalancers\",\"item\":\"https:\/\/www.fir3net.com\/networking\/loadbalancers\/f5-big-ip\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"F5 LTM – iRule Variables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.fir3net.com\/#website\",\"url\":\"https:\/\/www.fir3net.com\/\",\"name\":\"Fir3net\",\"description\":\"Keeping you in the know\",\"publisher\":{\"@id\":\"https:\/\/www.fir3net.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.fir3net.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.fir3net.com\/#organization\",\"name\":\"Fir3net\",\"url\":\"https:\/\/www.fir3net.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.fir3net.com\/wp-content\/uploads\/Fir3net-Background-Logo-compressed.png\",\"contentUrl\":\"https:\/\/www.fir3net.com\/wp-content\/uploads\/Fir3net-Background-Logo-compressed.png\",\"width\":390,\"height\":88,\"caption\":\"Fir3net\"},\"image\":{\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/person\/ab35009601b7687ee1c5310be6038037\",\"name\":\"Rick Donato\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.fir3net.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d75d69a54c0ca3b32c24c3a9703b623c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d75d69a54c0ca3b32c24c3a9703b623c?s=96&d=mm&r=g\",\"caption\":\"Rick Donato\"},\"description\":\"Rick Donato is a Network Automation Architect\/Evangelist and the founder of Packet Coders.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"F5 LTM - iRule Variables - Fir3net","description":"The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html","og_locale":"en_US","og_type":"article","og_title":"F5 LTM - iRule Variables - Fir3net","og_description":"The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article","og_url":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html","og_site_name":"Fir3net","article_published_time":"2013-09-01T00:00:00+00:00","article_modified_time":"2021-07-24T17:20:34+00:00","author":"Rick Donato","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rick Donato","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html#article","isPartOf":{"@id":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html"},"author":{"name":"Rick Donato","@id":"https:\/\/www.fir3net.com\/#\/schema\/person\/ab35009601b7687ee1c5310be6038037"},"headline":"F5 LTM – iRule Variables","datePublished":"2013-09-01T00:00:00+00:00","dateModified":"2021-07-24T17:20:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html"},"wordCount":384,"publisher":{"@id":"https:\/\/www.fir3net.com\/#organization"},"articleSection":["F5 Loadbalancers"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html","url":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html","name":"F5 LTM - iRule Variables - Fir3net","isPartOf":{"@id":"https:\/\/www.fir3net.com\/#website"},"datePublished":"2013-09-01T00:00:00+00:00","dateModified":"2021-07-24T17:20:34+00:00","description":"The F5 offers a number of different ways to you can represent your data via iRules such as variables, tables, datagroups and arrays. Within this article","breadcrumb":{"@id":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.fir3net.com\/Loadbalancers\/F5-BIG-IP\/f5-ltm-irule-variables.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.fir3net.com\/"},{"@type":"ListItem","position":2,"name":"Networking","item":"https:\/\/www.fir3net.com\/networking"},{"@type":"ListItem","position":3,"name":"Loadbalancers","item":"https:\/\/www.fir3net.com\/networking\/loadbalancers"},{"@type":"ListItem","position":4,"name":"F5 Loadbalancers","item":"https:\/\/www.fir3net.com\/networking\/loadbalancers\/f5-big-ip"},{"@type":"ListItem","position":5,"name":"F5 LTM – iRule Variables"}]},{"@type":"WebSite","@id":"https:\/\/www.fir3net.com\/#website","url":"https:\/\/www.fir3net.com\/","name":"Fir3net","description":"Keeping you in the know","publisher":{"@id":"https:\/\/www.fir3net.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.fir3net.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.fir3net.com\/#organization","name":"Fir3net","url":"https:\/\/www.fir3net.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fir3net.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.fir3net.com\/wp-content\/uploads\/Fir3net-Background-Logo-compressed.png","contentUrl":"https:\/\/www.fir3net.com\/wp-content\/uploads\/Fir3net-Background-Logo-compressed.png","width":390,"height":88,"caption":"Fir3net"},"image":{"@id":"https:\/\/www.fir3net.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.fir3net.com\/#\/schema\/person\/ab35009601b7687ee1c5310be6038037","name":"Rick Donato","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.fir3net.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d75d69a54c0ca3b32c24c3a9703b623c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d75d69a54c0ca3b32c24c3a9703b623c?s=96&d=mm&r=g","caption":"Rick Donato"},"description":"Rick Donato is a Network Automation Architect\/Evangelist and the founder of Packet Coders."}]}},"_links":{"self":[{"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/posts\/800"}],"collection":[{"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/comments?post=800"}],"version-history":[{"count":0,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/posts\/800\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/media?parent=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/categories?post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fir3net.com\/wp-json\/wp\/v2\/tags?post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}