Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Issue with implementing an irule through a script.

Andrew_L
Nimbostratus
Nimbostratus

I'm currently trying to implement an iRule using tmsh from within a bash script, but this results in an error that I've not been able to find information on.

 

The scripted command:

 

tmsh create ltm rule /Common/AppName.app/AppName_redir301_irule \

  when HTTP_REQUEST priority 200 { \

    set Redirect \"404\"\

    if { [info exists \"Redirect\"] } {\

      HTTP::respond 301 Location $Redirect \

      HTTP::respond replace Cache-Control no-cache ;\

      event disable all\

      }\

    }

 

The error:

 

01070151:3: Rule [/Common/AppName.app/AppName_redir301_irule] error: /Common/AppName.app/AppName_redir301_irule:1: error: [wrong # args][set Redirect "404" if { [info exists "Redirect"] } { HTTP::respond replace Cache-Control no-cache event disable all } ]

 

As far as I can tell there's no missing argument or extra argument to be found.

I've checked for whitespaces that aren't plain spaces (and retyped it manually just to be sure there isn't an artifact from cutting and pasting).

I've tried entering it from the command line within tmsh itself.

The only way that it seems to work is if I enter it from the webGUI (Local Traffic >> iRules >> iRule list >> AppName_redir301_irule), after which no error message results at all. (note: the trailing backslashes are removed)

Unfortunately entering it from the command line isn't an option (this will go on a remote system that I don't have access to, via an operator who solely runs scripts).

Can someone show me where I've gone wrong?

 

Thanks,

Andrew

 

 

1 REPLY 1

You may try a cli tmsh script and trigger the cli script from REST-API external script or bash script:

 

 

 

https://clouddocs.f5.com/cli/tmsh-reference/v14/modules/cli/cli_script.html

 

 

https://clouddocs.f5.com/api/tmsh/

 

 

https://clouddocs.f5.com/api/tmsh/script__run.html

 

 

 

 

Also you may use the REST-API and add the irule from system like Ansible without any local cli or bash scripts at all:

 

 

https://docs.ansible.com/ansible/latest/collections/f5networks/f5_modules/bigip_irule_module.html