1414 - An ansible-rulebook event source plugin for receiving events via a kafka topic.
1515options:
1616 host:
17- description:
1817 - The host where the kafka topic is hosted.
1918 type: str
20- required: true
19+ required: false
2120 port:
2221 description:
2322 - The port where the kafka server is listening.
24- type: str
25- required: true
23+ type: false
24+ brokers:
25+ description:
26+ - A list of host[:port] strings
27+ that the consumer should contact to bootstrap initial cluster metadata.
28+ This does not have to be the full node list.
29+ It just needs to have at least one broker that will respond to a Metadata API Request
30+ type: list(str)
31+ required: false
2632 cafile:
2733 description:
2834 - The optional certificate authority file path containing certificates
126132EXAMPLES = r"""
127133- ansible.eda.kafka:
128134 host: "localhost"
129- port: "9092"
135+ port: 9092
136+ brokers:
137+ - broker-1:9092
138+ - broker-2:9093
139+ - broker-3:9094
130140 check_hostname: true
131141 verify_mode: "CERT_OPTIONAL"
132142 encoding: "utf-8"
@@ -163,6 +173,7 @@ async def main( # pylint: disable=R0914
163173
164174 host = args .get ("host" )
165175 port = args .get ("port" )
176+ brokers = args .get ("brokers" )
166177 cafile = args .get ("cafile" )
167178 certfile = args .get ("certfile" )
168179 keyfile = args .get ("keyfile" )
@@ -174,6 +185,18 @@ async def main( # pylint: disable=R0914
174185 encoding = args .get ("encoding" , "utf-8" )
175186 security_protocol = args .get ("security_protocol" , "PLAINTEXT" )
176187
188+ if host and brokers :
189+ msg = "Only one of host and brokers parameter must be set"
190+ raise ValueError (msg )
191+
192+ if (host and not port ) or (port and not host ):
193+ msg = "Port and host must be set"
194+ raise ValueError (msg )
195+
196+ if not host and not brokers :
197+ msg = "host + port or brokers must be set"
198+ raise ValueError (msg )
199+
177200 if offset not in ("latest" , "earliest" ):
178201 msg = f"Invalid offset option: { offset } "
179202 raise ValueError (msg )
@@ -202,7 +225,7 @@ async def main( # pylint: disable=R0914
202225 ssl_context .verify_mode = verify_mode
203226
204227 kafka_consumer = AIOKafkaConsumer (
205- bootstrap_servers = f"{ host } :{ port } " ,
228+ bootstrap_servers = brokers if brokers else f"{ host } :{ port } " ,
206229 group_id = group_id ,
207230 enable_auto_commit = True ,
208231 max_poll_records = 1 ,
0 commit comments