Closed DawidNiezgodka closed 9 months ago
Hi @DawidNiezgodka . It looks like you may be providing this value as a string vs. an array. For example, you have the following:
kafka_advertised_listeners: "[\"PLAINTEXT://{{ansible_ssh_host}}:9092\"]"
This Ansible role takes an array and then joins the entries using commas. https://github.com/sleighzy/ansible-kafka/blob/master/templates/server.properties.j2#L54
Could you try something like the below instead and see if this works for you:
kafka_advertised_listeners:
- PLAINTEXT://{{ansible_ssh_host}}:9092
Thanks for the quick reply.
Hmm, it does not work. I tried both:
- PLAINTEXT://{{ansible_ssh_host}}:9092
"PLAINTEXT://{{ansible_ssh_host}}:9092"
Indentation seems correct, i.e., space, space, -, space, PLA...
The workaround I found is to set kafka_start: no
, and then:
- name: Add advertised.listeners to server.properties
hosts: kafka-nodes
tasks:
- name: Add advertised.listeners line
lineinfile:
path: /etc/kafka/server.properties
line: "advertised.listeners=PLAINTEXT://{{ansible_ssh_host}}:9092"
create: no
- name: Start kafka service
service:
name: kafka
state: started
enabled: yes
However, I'd be happy to find the culprit and use it directly ;)
here is working code
and my tip to work with quote, you can use double quote inside single code, or vice versa (output is same with escape notation)
kafka_advertised_listeners: "['PLAINTEXT://{{ansible_ssh_host}}:9092']"
Thanks for that response, much appreciated. I’ll do some tests on my end and update the role and readme so this works as expected.
I've done a test on my end and have replicated your issue. When I use the below block with ansible_ssh_host
then it fails to put that entry in the server.properties
file.
kafka_advertised_listeners:
- 'SASL_SSL://{{ansible_ssh_host}}:9094'
- 'PLAINTEXT://{{ansible_ssh_host}}:9092'
Looking at these docs (yes they're slightly older) https://docs.ansible.com/archive/ansible/2.4/intro_inventory.html they mentioned that ansible_ssh_host
has been deprecated in favour of ansible_host
. I then tested using ansible_host
instead and that worked, the entry was there and the entry popluated.
kafka_advertised_listeners:
- 'SASL_SSL://{{ansible_host}}:9094'
- 'PLAINTEXT://{{ansible_host}}:9092'
# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
#advertised.listeners=PLAINTEXT://your.host.name:9092
advertised.listeners=SASL_SSL://server-2:9094,PLAINTEXT://server-2:9092
Have a try on your end and see if you get the expected results.
Closing this issue now as should be enough info re: Ansible config to resolve it.
I want to set up
advertised.listeners
, but the value won't resolve. Even though the variable is set in the config, one can see the following:#advertised.listeners=PLAINTEXT://your.host.name:9092
Here's the complete playbook:
The way the value is passed seems correct. When I run the following task, it gives me the value correctly:
->