How would one audit/check tags assigned to networks?


I am using tags for my network selection. I have been trying to find a way to extract all networks with tags, tried via code and db, but havent found a way yet…

running ruby script in cf irb, the variables aren’t makig it into the $evm.vmdb(:lan).all.each do |network| loop

envname = "nonprod"
zone = "green"
site = "d3"
network_location = “data”
$evm.vmdb(:lan).all.each do |network|
if network.tagged_with?(:zone, zone) &&
network.tagged_with?(:site, site) &&
network.tagged_with?(:envname, envname) &&
network.tagged_with?(:network_location, network_location)
selected_network <<

In the db SELECT * from lans; doesn’t have a field for tags…


Have you actually tagged the lans? If not, all those tagged_with? checks will return false. If you wanted to just dump the tags each had for a sanity check, you could call tags on the network object.

Yep there are tagged lans. In the end I am just interested in getting all networks that are tagged with specific tags, but there is probably a use case for all tags on all lans too.

To be more precise, the code block actually works, but as soon as I put an outer loop in it (reading comma separated values from a file to populate the tag combination) it stops working. The values make it from the file to the variables but not into the inner loop when running in cf irb console…

Anyway, was thinking this should be a fairly comma use case, i.e. reporting/reviewing/auditing tags in cf? Specific to lans/networks would be great for now.


If that’s your use case, I imagine this page from the automate book will be very useful to you, particularly the find_tagged_with method.

1 Like

Nice one. Let me give it a go. Thanks

Turned out to be a ruby thing in the end. I am using a csv file to loop through all the required tag combinations. Initially I was using and then split each line. Assigning the elements to vars worked, but seemed to not survive to inside the “$evm.vmdb(:lan).all.each do |network|” loop. Switching to CSV.foreach fixed the issue. Ruby’s encoding of the element strings are different for the two approaches.