kafka_server role variable not being merged correctly with kafka_server_defaults #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In modern versions of Ansible (I'm using version 2.6.1, which this bug applies to) there is new behavior of
set_fact
, whereset_fact
no longer overrides role variables (see Ansible 22025 for a discussion of this). When passing in the role variablekafka_server
via a playbook, this variable will not be merged properly withkafka_server_defaults
, since the result of the merge is re-assigned back tokafka_server
. This will cause problems when executing the role, askafka_server
will likely not contain much of the needed properties. As an example, try running the playbook:The result will be an error of the form:
FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'port'\n\nThe error appears to have been in '/home/bradleysheppard/Dev/AnsibleKafka/ansible-kafka/tasks/kafka-cfg.yml': line 31, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: \"Generate the kafka hosts connection string\"\n ^ here\n"}
The fix involves not reassigning the result of the merge back to
kafka_server
, but instead using a new variable, which I have calledkafka_server_config
.