StephenSorriaux / ansible-kafka-admin

Manage your topic's configuration (partitions, replication factor, parameters), ACLs, quotas, users and get stats, without any effort with this library. It does not use the Kafka scripts and does not require ssh connection to the remote broker.
Apache License 2.0
150 stars 46 forks source link

kafka_topic: invalid check_mode behaviour when updating an existing topic #137

Closed saiello closed 1 year ago

saiello commented 2 years ago

Expected Behavior

Running kafka_topic module in check mode, to update a topic, should reflect actual behaviour and report potential changes.

Actual Behavior

Running in check mode reports " Nothing to do", however removing the --check option perform the updates.

Ad-hoc commands to Reproduce the Problem

  1. Create a topic
    ansible -m kafka_topic localhost -a 'bootstrap_servers=localhost:9092 name=sample-topic partitions=3 replica_factor=1 state=present'
localhost | CHANGED => {
    "changed": true,
    "changes": {
        "topic_created": [
            {
                "force_reassign": false,
                "name": "sample-topic",
                "options": {},
                "partitions": 3,
                "preserve_leader": false,
                "replica_factor": 1,
                "state": "present"
            }
        ]
    },
    "msg": "topic sample-topic successfully created. "
}
  1. Check for topic options update
ansible -m kafka_topic localhost -a 'bootstrap_servers=localhost:9092 name=sample-topic partitions=3 replica_factor=1 options={{ options }}' -e '{"options": { "retention.ms": 100000}}' --check 
localhost | SUCCESS => {
    "changed": false,
    "changes": {},
    "msg": "nothing to do."
}
  1. Execute topic's options update
ansible -m kafka_topic localhost -a 'bootstrap_servers=localhost:9092 name=sample-topic partitions=3 replica_factor=1 options={{ options }}' -e '{"options": { "retention.ms": 100000}}'
localhost | CHANGED => {
    "changed": true,
    "changes": {
        "topic_updated": [
            "sample-topic"
        ]
    },
    "msg": "topic sample-topic successfully updated. "
}
saiello commented 2 years ago

The problem might be in the implementation of these lines:

        // module_utils/kafka_lib_topic.py   [63-74]

        if len(topics_to_maybe_update) > 0:
            if not module.check_mode:
                topics_changed, warn = manager.ensure_topics(
                    topics_to_maybe_update
                )
                changed = len(topics_changed) > 0
                if changed:
                    msg += ''.join(['topic %s successfully updated. ' %
                                    topic for topic in topics_changed])
                    changes.update({
                        'topic_updated': topics_changed
                    })
saiello commented 2 years ago

I've realized the issue might be resolved in #103. I will check it