I have to set the stage a little first. The application is kafka.
End goal: I want to be able to make kafka config match what I provide in the dictionary (specifically topics). Adding topics to make kafka match is easy. The part I'm having problem is removing topics from kafka if they are not in the dictionary. The only variable I ened to provide kafka is the "topic name" in order to delete.
I can obtain a list of currently added topics from kafka as a variable we will call {{ existing }}. It looks like this:
topic1
topic2
topic3
topic4
My dictionary is as follows:
kafka_topics:
topic1:
partitions: 1
replication_factor: 1
topic2:
partitions: 1
replication_factor: 1
How do I take action on topic3 and topic4 because they are not part of the dict?
At first glance, you just say do a
if {{existing}} != {{item.key}} then do action
but that does not work because it only checks 1 key at a time. If the types were reversed the list were a dict, dict was a list) you could easily do it by saying if topics contains existing, then do action.
There has GOT to be a better way to do this.