Forum Discussion
danra_139044
Apr 30, 2014Altostratus
Add irule via tmsh without deleting existing irules, and how to re-order
In v11.5 - need assistance in adding irules via tmsh, without deleting existing irules.
tmsh modify /ltm virtual rules { irulename } this removes all the applied irules and only adds the new i...
Thomas_Brown_12
Nimbostratus
Until F5 incorporates this feature request into the product I wrote two scripts to allow appending an iRule to as well as deleting an iRule from an existing virtual:
!/bin/sh
f5-irule-add - add iRule to virtual server, preserving existing iRule configuration
Thomas Brown, CA Technologies - Mon Aug 1 15:21:29 GMT 2016 - initial version
Parse command line arguments
if [ $ -ne 2 ]; then
echo "Usage: $0 virtual irule" >&2
exit 1
fi
virtual=$1
irule_add=$2
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
fi
fi
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
!/bin/sh
f5-irule-delete - delete iRule from virtual server, preserving existing iRule configuration
Thomas Brown, CA Technologies - Mon Aug 1 15:52:03 GMT 2016 - initial version
Parse command line arguments
if [ $ -ne 2 ]; then
echo "Usage: $0 virtual irule" >&2
exit 1
fi
virtual=$1
irule_del=$2
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; exiting"
exit 2
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_del} ]; then
exists=1
fi
done
if [ ${exists} -eq 0 ]; then
echo "$0: ${irule_del} does not exist in virtual ${virtual}" >&2
exit 2
else
irule_current=`echo " ${irule_current} " | sed -e "s/ ${irule_del} / /"`
fi
fi
Modify iRule list
command="echo tmsh modify ltm virtual ${virtual} rules { ${irule_current} }"
echo ${command}
exec ${command}
status=$?
if [ ${status} -ne 0 ]; then
echo "tmsh returned error status ${status}" >&2
exit ${status}
fi
danielm1
Nov 11, 2016Cirrus
Thanks Thomas for sharing.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects