I came across the scenario where I need to add 200 specific IPs to the datagroup list. Rather than adding it manually, is there a way i can do it via cli? Can you please post the complete command/script to do this.
Well if its an internal DG, you can follow the below,
Step 1 : Do a list of the existing records and copy it to a file. If the list is small, copy it to a text file and save it in the local desktop.
Command : tmsh list ltm data-group internal
Eg : AOL which is a F5 default dg. Make sure you copy this part too.
ltm data-group internal aol {
records {
IP's
}
type ip
}
Step 2: Once the IP’s and the keywords are copied to a text file, paste the new 200 IP’s as per the subnets required inbetween the records section { } , without adding subnets will make it default /32.
Step 3: Winscp the txt file to the LTM, or you can create it in the F5 /var/tmp/ location itself.
Step 4: Merge the uploaded file or the tmp location file.
NOTE: Make sure you add the merge command at the end, else your entire config will be replaced with this txt file alone. There wont be any config left and your box will go config less…
!/bin/sh
Uncomment the following line if your data group does not yet exist.
tmsh create ltm data-group internal test_dg type ip records add { 9.9.9.9 }
for i in `cat /tmp/address_list`
do
tmsh modify ltm data-group internal test_dg records add { $i }
done
tmsh list ltm data-group internal test_dg
If you see the following output:
ltm data-group internal test_dg {
records {
1.1.1.1/32 { }
2.2.2.2/32 { }
3.3.3.3/32 { }
4.4.4.4/32 { }
5.5.5.5/32 { }
9.9.9.9/32 { }
}
type ip
}
In case this helps anyone in the future you can simpy just use a GET on one F5 device and then a PUT or PATCH on the device you want to move the datagroup to. I’ve used powershell and the existing LTM module to leverage sessions but you can do this in any language.