We are currently running on software version 11.6 and we have an iRule that we would like to remove from some 200 VIP’s that we have.
I found and recreated the bulk script located here: DevCentral - An F5 Technical Community
When I attempt to run it, it says “The TestRule iRule was removed from the following virtuals:”
and then nothing else after it. The VIPS in question are in a /Customers partition and the iRule is in the /Common partition. Thinking that was a problem I added an iRule that is in the /Customer partition to a vip and still the same results. Would there need to be any changes made to the script to make it work for 11.6?
Hi Robberhines,
the script is still okay in 11.6, but it was just never designed to support iRules in other partitions then /Common.
To support the removal of iRules bound on VS in multiple partitions, the scripts needs to iterate the available partitions step-by-step. So you may want to try this customized script…
proc script::run {} {
if { $tmsh::argc != 2 } then {
puts "A single rule name must be provided"
exit
}
set qualified_rulename [lindex $tmsh::argv 1]
set vips_in_play ""
foreach partition [tmsh::get_config auth partition] {
set partition "/[tmsh::get_name $partition]"
puts "Crawling Partition: $partition"
tmsh::cd $partition
if { $qualified_rulename starts_with $partition } then {
set rulename [string trim $qualified_rulename $partition]
} else {
set rulename $qualified_rulename
}
set vips [tmsh::get_config /ltm virtual]
tmsh::begin_transaction
foreach vip $vips {
puts "\tCrawling VS : $partition/[tmsh::get_name $vip]"
if { [tmsh::get_field_value $vip "rules" rules] == 0 } then {
puts "\tFinished VS: No Rules bound to the VS"
continue
}
if { [lsearch -exact $rules $rulename] == -1 } then {
puts "\tFinished VS: $rulename is not bound to VS"
continue
}
if { [llength $rules] < 2 } then {
puts "\tFinished VS: $rulename is removed from VS"
tmsh::modify /ltm virtual [tmsh::get_name $vip] rules none
} else {
puts "\tFinished VS: $rulename is removed from VS"
set id [lsearch -exact $rules $rulename]
set keepers [lreplace $rules $id $id]
tmsh::modify /ltm virtual [tmsh::get_name $vip] rules "{ $keepers }"
}
lappend vips_in_play "$partition/[tmsh::get_name $vip]"
}
tmsh::commit_transaction
puts "Finished Partition: $partition"
}
if { $vips_in_play ne "" } then {
puts "The provided iRule $rulename was removed from the following virtuals:"
foreach vip_in_play $vips_in_play {
puts "\t$vip_in_play"
}
} else {
puts "The provided iRule $rulename was not found on any virtual."
}
}
Note: You have to uncomment every instance of “tmsh::modify” to perform the actual changes. Without, the script would just simulate the changes and output some debug lines.
[itacs@f5-02:Active:Standalone] / tmsh run cli script file script.tcl /Common/Test2
Crawling Partition: /Common
Crawling VS : /Common/VS_HTTPS_210
Finished VS: Test2 is removed from VS
Crawling VS : /Common/VS_HTTPS_211
Finished VS: Test2 is removed from VS
Crawling VS : /Common/VS_HTTP_192-224
Finished VS: Test2 is removed from VS
Finished Partition: /Common
Crawling Partition: /test
Crawling VS : /test/test
Finished VS: /Common/Test2 is removed from VS
Finished Partition: /test
The provided iRule /Common/Test2 was removed from the following virtuals:
/Common/VS_HTTPS_210
/Common/VS_HTTPS_211
/Common/VS_HTTP_192-224
/test/test
Note2: Test it carefully in a non-production environment. Its somewhat hot smoked… 
Cheers, Kai
This worked perfectly. Thanks for the help!
You’re welcome. Cheers, Kai BTW: Catched a little bug. Change [string trim $qualified_rulename $partition] to [string range $qualified_rulename [expr { [string last “/” $qualified_rulename] + 1}] end].