Forum Discussion
Convert iRule File to use in curl command
Hi Mike,
With help of curl command you can send irule to F5 box but you need to lot of background work. Example:
curl -sku admin:<password> -H "Content-Type: application/json" -X POST https://<BIG-IP_host>/mgmt/tm/ltm/rule -d '{"name":"<iRule_name>","apiAnonymous":"<iRule_content>"}' | jq .
i.e.
curl -sku admin:testing -H "Content-Type: application/json" -X POST https://LTM1.example.com/mgmt/tm/ltm/rule -d '{"name":"example_rule","apiAnonymous":"when HTTP_REQUEST {\n if { [HTTP::uri] ends_with \"test\" } {\n pool test_pool\n }\n}"}' | jq .
Output similar to this...
The output looks similar to the following example:
{
"kind": "tm:ltm:rule:rulestate",
"name": "example_rule",
"partition": "Common",
"fullPath": "/Common/example_rule",
"generation": 2184,
"selfLink": "https://BIGIP_IP/mgmt/tm/ltm/rule/~Common~example_rule?ver=15.1.0",
"apiAnonymous": "when HTTP_REQUEST {\n if { [HTTP::uri] ends_with \"test\" } {\n pool test_pool\n }\n}"
}
I would suggest you to use ansible playbook to copy irule to f5 bigip.
---
#
# For More Irule help - https://www.linkedin.com/in/welcomesamir/
#
- name: BIG-IP SETUP
hosts: lb
connection: local
gather_facts: false
vars:
irules: ['testirule','test2_irule']
tasks:
- set_fact:
provider:
server: "{{private_ip}}"
user: "{{ansible_user}}"
password: "{{ansible_ssh_pass}}"
server_port: 443
validate_certs: no
- name: ADD iRules
bigip_irule:
provider: "{{provider}}"
module: "ltm"
name: "{{item}}"
content: "{{lookup('file','{{item}}')}}"
with_items: "{{irules}}"
thanks
- Mike_BrandtJul 17, 2023
Nimbostratus
Thanks Samir !
I was actually looking to see if anyone knew of some command line foo to convert the irule contents to be used as the JSON value aligned with the "apiAnonymous" key. Is there a way to use something like sed to insert '\n' characters as well as do any necessary quotation escapes in order to push the file that way.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
