diff --git a/README.md b/README.md index 711565ee..f697338d 100644 --- a/README.md +++ b/README.md @@ -372,6 +372,26 @@ Playbook: } } ``` +#### Topics-Configuration +Playbook: +```yaml +- name: get topics configuration + kafka_info: + resource: "topic-config" + bootstrap_servers: "{{ ansible_ssh_host }}" + api_version: "{{ kafka_api_version }}" + register: topics +``` +`topics` will be: +```json +{ + "": { + "test_1600292339": { + "retention.ms": "66574936" + } + } +} +``` #### Consumer groups Playbook: ```yaml diff --git a/library/kafka_info.py b/library/kafka_info.py index 6dcad8d5..44e05799 100644 --- a/library/kafka_info.py +++ b/library/kafka_info.py @@ -34,7 +34,8 @@ description: - 'the type of resource to get information about' required: True - choices: [topic, broker, consumer_group, acl] + choices: [topic, broker, consumer_group, acl, + topic-config] ''' + DOCUMENTATION_COMMON EXAMPLES = ''' @@ -58,7 +59,13 @@ def main(): module = AnsibleModule( argument_spec=dict( resource=dict( - choices=['topic', 'broker', 'consumer_group', 'acl'], + choices=[ + 'topic', + 'broker', + 'consumer_group', + 'acl', + 'topic-config' + ], required=True ), **module_commons diff --git a/module_utils/kafka_manager.py b/module_utils/kafka_manager.py index d5ad2f31..174c2f80 100644 --- a/module_utils/kafka_manager.py +++ b/module_utils/kafka_manager.py @@ -1035,6 +1035,20 @@ def get_brokers_resource(self): brokers[broker.nodeId] = broker._asdict() return brokers + def get_topics_config(self): + """ +Return a dict object containing information about configuration +of topics and partitions, and following this structure: +{ + "test_1600378061": { + "config-key": "config-value" + } +} + """ + topics = self.get_topics() + return self.get_config_for_topics({ + topic: {} for topic in topics}) + def get_topics_resource(self): """ Return a dict object containing information about topics and partitions, @@ -1238,6 +1252,7 @@ def get_acls_resource(self): def resource_to_func(self): return { 'topic': self.get_topics_resource, + 'topic-config': self.get_topics_config, 'broker': self.get_brokers_resource, 'consumer_group': self.get_consumer_groups_resource, 'acl': self.get_acls_resource diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index eddfa39d..52907233 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -535,6 +535,39 @@ def test_kafka_info_topic(host): assert not partition_info['unavailable_partition'] +def test_kafka_info_topics_config(host): + """ + Check if can get config on topic. + """ + # Given + topic_name = get_topic_name() + test_topic_configuration = topic_defaut_configuration.copy() + test_topic_configuration.update({ + 'options': { + 'retention.ms': 66574936 + } + }) + ensure_topic( + host, + test_topic_configuration, + topic_name + ) + time.sleep(0.3) + # When + results = call_kafka_info( + host, + { + 'resource': 'topic-config' + } + ) + # Then + for r in results: + assert topic_name in r['ansible_module_results'] + for name, topic_config in r['ansible_module_results'].items(): + if name == topic_name: + assert int(topic_config['retention.ms']) == 66574936 + + def test_kafka_info_brokers(host): """ Check if can get info on brokers