-
Notifications
You must be signed in to change notification settings - Fork 46
/
kafka_users.py
104 lines (86 loc) · 2.32 KB
/
kafka_users.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Ansible module for users configuration management
"""
from __future__ import absolute_import, division, print_function
__metaclass__ = type
# Init logging
import logging
import sys
# XXX: fix kafka-python import broken for Python 3.12
import ansible.module_utils.kafka_fix_import # noqa
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.kafka_lib_user import (
process_module_users, module_user_spec_commons
)
from ansible.module_utils.kafka_lib_commons import (
module_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_users
short_description: Manage Kafka users
description:
- Configure Kafka users.
- Not compatible avec Kafka version < 0.11.0.
author:
- Stephen SORRIAUX
- ryarnyah
options:
mark_others_as_absent:
description:
- make non listed users as absent, thus triggering the deletion
- of users absent from the `users` listing
users:
description:
- users to create. @See kafka_user for options
... tbc ...
''' + DOCUMENTATION_COMMON
EXAMPLES = '''
# creates users deleting the others
- name: create users
kafka_users:
mark_others_as_absent: yes
users:
- name: 'user1'
password: changeit
mechanism: SCRAM-SHA-512
state: 'present'
- name: 'user2'
mechanism: SCRAM-SHA-512
state: 'absent'
bootstrap_servers: localhost:9092
'''
def main():
"""
Module usage
"""
spec = dict(
mark_others_as_absent=dict(type='bool', default=False),
users=dict(
type='list',
elements='dict',
required=True,
options=dict(
**module_user_spec_commons
)
),
**module_commons
)
module = AnsibleModule(
argument_spec=spec,
supports_check_mode=True
)
process_module_users(module, None)
if __name__ == '__main__':
main()