Forum Discussion
How to add iRules using CLI
Hi, team,
I'm looking for the command to add iRule, since I have to apply about 40 same iRule to Virtual servers. I tried command which I learned from Q&A below, but it delete current iRules.
tmsh modify ltm virtual ABC.COM-HTTP rules { Maintenance-Irule }
ABC.COM-HTTP = Virtual Server, Maintenance-Irule = iRule which I want to add
Could you tell me how can I just ADD the iRule? Thanks in advance for your help, Naoki
- Gian_L__V__HenrNimbostratus
I've done this same task with this script I've made. I add an iRule preserving all existing ones on the Virtual Server.
#!/bin/sh
# f5-irule-add - add iRule to a virtual server, preserving existing iRule configuration
# Gian Henriques, 30/06/2021
# hot to use: ./script.sh new_irule my_vs
virtual=$2
irule_add=$1
#Capture existing iRule configuration
tmsh list ltm virtual ${virtual} one-line | grep -q " rules { "
if [ $? -eq 1 ]; then
echo "$0: ${virtual} currently contains no rules; adding new rule"
irule_current=""
else
irule_current=`tmsh list ltm virtual ${virtual} one-line | sed -e 's/.* rules { //' -e 's/ }.*//'`
# Check if rule already exists
exists=0
for rule in ${irule_current}
do
if [ ${rule} == ${irule_add} ]; then
exists=1
fi
done
if [ ${exists} -eq 1 ]; then
echo "$0: ${irule_add} already exists in virtual ${virtual}" >&2
#exit 2
else
# Modify iRule list
command="tmsh modify ltm virtual ${virtual} rules { ${irule_current} ${irule_add} }"
echo ${command}
exec ${command}
status=$?
if [ ${status} -ne 0 ]; then
echo "tmsh returned error status ${status}" >&2
exit ${status}
fi
fi
fi
- nitassEmployee
Could you tell me how can I just ADD the iRule?
i am afraid you have to specify all the irules.
- Seth_CooperEmployee
You could still automate this but for each virtual you would have to run a list command and then parse the output.
for all in `tmsh list ltm virtual VIRTUAL_NAME rules | egrep -v "\{|\}"` > do > echo $all > done firepass_assign
This is a sample that will allow you to loop through the current rules assigned.
When you have the current values then append the new iRule on the list and then run your modify command with all the iRules specified.
Seth
You can automate the irule addition to the Virtual server with the below scripts. Create a file virtual_list and paste all the virtual servers for which you need to add the new irule.
!bin/bash for i in $(cat virtual_list) do rule=`tmsh list ltm virtual $i rules | egrep -v "\{|\}"` echo "irule is ${rule//[[:blank:]]/} and virtual is $i" modify ltm virtual $i rules { ${rule//[[:blank:]]/} new-irule-name } echo " rule added successfully " done
- Nandhini_NataraNimbostratus
You can automate the irule addition to the Virtual server with the below scripts. Create a file virtual_list and paste all the virtual servers for which you need to add the new irule.
!bin/bash for i in $(cat virtual_list) do rule=`tmsh list ltm virtual $i rules | egrep -v "\{|\}"` echo "irule is ${rule//[[:blank:]]/} and virtual is $i" modify ltm virtual $i rules { ${rule//[[:blank:]]/} new-irule-name } echo " rule added successfully " done
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