Cp-ansible: Namespace of Variable {{broker.id}} In Kafka Broker server properties file

Created on 2 Apr 2019  ·  5Comments  ·  Source: confluentinc/cp-ansible

In the template file for the kafka broker properties, we use the variable {{kafka.broker.id}} referring to the inventory file hosts.yml. But the {{kafka}} variable is defined in the role's defaults.

This will still run correctly because of Ansible's hierarchy of variable precedence, as in the value of {{kafka.broker.id}} will first be taken from the inventory_host dictionary, but for clarity it would be better not to mix namespaces.

I think we should use {{ inventory_hostname.kafka.broker.id }} to make this clear.

enhancement

Most helpful comment

I see now this is what the merge property of ansible.cfg is doing. I still think this makes the playbook less readable and harder to learn from.

All 5 comments

Same thing happens with listeners=PLAINTEXT://:{{broker.config.port}}. In that case, {{broker}} comes from the confluent.common/defaults/main.yml. Namespacing better here will make things more clear.

I see now this is what the merge property of ansible.cfg is doing. I still think this makes the playbook less readable and harder to learn from.

I suffer same trouble when I run 'confluent.kafka-broker' role today and spend several hours finding it.

@chuck-confluent - I ran into this situation today. When I update the base_server_properties Jinja template to use broker.id={{ inventory_hostname.kafka.broker.id }} and re-run Ansible I get the following error. Still trying to debug why.

TASK [confluent.kafka-broker : broker sasl_ssl config] *********************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.parsing.yaml.objects.AnsibleUnicode object' has no attribute 'kafka'"}

@chuck-confluent we just merged the following PR, which makes most if not all properties overridable. Should resolve the issues you are seeing.

https://github.com/confluentinc/cp-ansible/pull/124

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fobhep picture Fobhep  ·  7Comments

OneCricketeer picture OneCricketeer  ·  7Comments

Fobhep picture Fobhep  ·  12Comments

LGouellec picture LGouellec  ·  4Comments

Fobhep picture Fobhep  ·  12Comments