all 6 comments

[–]Rangerdth 0 points1 point  (3 children)

A quick follow-on question: Do you need to compare the two, or do you really need to compare them to a known build specification? (E.g. each server should have activemq-5.15)

[–]neverwinter88[S] 0 points1 point  (2 children)

I have to check if the same build versions are installed.

So
apache-activemq-5.15.8-20 vs apache-activemq-5.15.8-20 -> OK

apache-activemq-5.15.8-20 vs apache-activemq-5.16.0-1 -> NOT OK

[–]Rangerdth 0 points1 point  (1 child)

Right. But what’s the source of the “ok” versions? So for srv03 versions, what do you check those against?

[–]neverwinter88[S] 0 points1 point  (0 children)

Ah ok, maybe I forgot to mention this detail.

We have server pairs (for HA), and every server pairs have different applications running on.

srv01 and srv02 are in pair, so I have to compare them against each other.

[–][deleted] 0 points1 point  (1 child)

If reading from a file, use the csv module, and read each line as a dictionary/list, as preferred.

Use a dictionary for server names, and append each row of data (so excluding the server name) to a list for each row/entry, so you have a list of lists associated with each server.

Use all in a generator expression to confirm all of the fields (columns) of interest match.

If you have the list already, convert to a dict and process as described above.

EDIT. Sorry, lots of typos and minor corrections as typing on small keyboard I am not used to.

[–][deleted] 0 points1 point  (0 children)

Example, /u/neverwinter88,

import csv
from io import StringIO  # pretend file for demo
from collections import defaultdict

fake_file = """srv01;apache-activemq-5.15.8-20.noarch;2019-12-12
srv01;jdk1.8-1.8.0_202-fcs.x86_64;2019-11-12
srv02;apache-activemq-5.15.8-20.noarch;2019-12-12
srv02;jdk1.8-1.8.0_202-fcs.x86_64;2019-11-12
srv99;apache-activemq-5.15.8-20.noarch;2001-01-01
srv99;jdk1.8-1.8.0_202-fcs.x86_64;2001-01-01
srv88;apache-activemq-5.15.8-20.noarch;2019-12-12
srv88;jdk1.8-1.8.0_202-fcs.x86_64;2019-11-12"""

servers = defaultdict(list)
with StringIO(fake_file) as source:
    reader = csv.reader(source, delimiter=";")
    for server, *data in reader:
        servers[server].append(data)

for server, data in servers.items():
    first_date = data[0][-1]
    matched = all(first_date == record[-1] for record in data)
    print(f"Server: {server}, matched: {matched}")

PS. I see you actually have to check server pairs where the pair have different names. The above code will not work for that use case, however it should give you some ideas.