forked from StephenSorriaux/ansible-kafka-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafka_topics.py
176 lines (158 loc) · 4.97 KB
/
kafka_topics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Ansible module for topics configuration management
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
# Init logging
import logging
import sys
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.kafka_lib_topic import process_module_topics
from ansible.module_utils.kafka_lib_commons import (
module_commons, module_zookeeper_commons, module_topic_commons,
DOCUMENTATION_COMMON
)
# Default logging
# TODO: refactor all this logging logic
log = logging.getLogger('kafka')
log.addHandler(logging.StreamHandler(sys.stdout))
log.setLevel(logging.INFO)
log = logging.getLogger('kazoo.client')
log.addHandler(logging.StreamHandler(sys.stdout))
log.setLevel(logging.INFO)
ANSIBLE_METADATA = {'metadata_version': '1.0'}
DOCUMENTATION = '''
---
module: kafka_topics
short_description: Manage Kafka topics
description:
- Configure Kafka topics.
- Not compatible avec Kafka version < 0.11.0.
author:
- Stephen SORRIAUX
- ryarnyah
options:
topics:
description:
- Topics to create. @See kafka_topic for options
mark_others_as_absent:
description:
- make non listed topics as absent, thus triggering the deletion
- of topics absent from the `topics` listing
zookeeper:
description:
- 'the zookeeper connection.'
zookeeper_auth_scheme:
description:
- 'when zookeeper is configured to use authentication, schema used to '
- 'connect to zookeeper.'
default: 'digest'
choices: [digest, sasl]
zookeeper_auth_value:
description:
- 'when zookeeper is configured to use authentication, value used to '
- 'connect.'
zookeeper_use_ssl:
description:
- 'force using ssl for zookeeper connection.'
default: False
zookeeper_ssl_check_hostname:
description:
- 'when using ssl for zookeeper, check if certificate for hostname is '
- 'correct.'
default: True
zookeeper_ssl_cafile:
description:
- 'when using ssl for zookeeper, content of ca cert file or path to '
- 'ca cert file.'
zookeeper_ssl_certfile:
description:
- 'when using ssl for zookeeper, content of cert file or path to '
- 'server cert file.'
zookeeper_ssl_keyfile:
description:
- 'when using ssl for zookeeper, content of keyfile or path to '
- 'server cert key file.'
zookeeper_ssl_password:
description:
- 'when using ssl for zookeeper, password for ssl_keyfile.'
zookeeper_sleep_time:
description:
- 'when updating number of partitions and while checking for'
- 'the ZK node, the time to sleep (in seconds) between'
- 'each checks.'
default: 5
zookeeper_max_retries:
description:
- 'when updating number of partitions and while checking for'
- 'the ZK node, maximum of try to do before failing'
default: 5
kafka_sleep_time:
description:
- 'when updating number of partitions and while checking for'
- 'kafka to applied, the time to sleep (in seconds) between'
- 'each checks.'
default: 5
kafka_max_retries:
description:
- 'when updating number of partitions and while checking for'
- 'kafka to applied, maximum of try to do before failing'
default: 5
''' + DOCUMENTATION_COMMON
EXAMPLES = '''
# creates a topic 'test' with provided configuation for plaintext
- name: create topics
kafka_topics:
topics:
- name: 'test'
partitions: 2
replica_factor: 1
options:
retention.ms: 574930
flush.ms: 12345
state: 'present'
zookeeper: >
"{{ hostvars['zk']['ansible_eth0']['ipv4']['address'] }}:2181"
bootstrap_servers: >
"{{ hostvars['kafka1']['ansible_eth0']['ipv4']['address'] }}:9092,
{{ hostvars['kafka2']['ansible_eth0']['ipv4']['address'] }}:9092"
# deletes a topic
- name: delete topic
kafka_lib:
topics:
- name: 'test'
state: 'absent'
zookeeper: >
"{{ hostvars['zk']['ansible_eth0']['ipv4']['address'] }}:2181"
bootstrap_servers: >
"{{ hostvars['kafka1']['ansible_eth0']['ipv4']['address'] }}:9092,
{{ hostvars['kafka2']['ansible_eth0']['ipv4']['address'] }}:9092"
'''
def main():
"""
Module usage
"""
spec = dict(
mark_others_as_absent=dict(type='bool', default=False),
topics=dict(
type='list',
elements='dict',
required=True,
options=dict(
name=dict(type='str', required=True),
state=dict(choices=['present', 'absent'], default='present'),
**module_topic_commons
)
),
**module_commons
)
spec.update(module_zookeeper_commons)
module = AnsibleModule(
argument_spec=spec,
supports_check_mode=True
)
process_module_topics(module)
if __name__ == '__main__':
main()