Closed herbertkb closed 4 months ago
Hello; the key for parameters under operations (and in general under any configuration that has parameters) needs to be a valid python variable name, ie. the java address-match
needs to be written as address_match
activemq_broker_connections:
- uri: vm://0
name: brokerA-2-brokerB
operations:
- type: sender
parameters:
address-match: 'b.#'
I noticed the error is present in the role documentation, so relabelling as "documentation" (unless you find other issues with this configuration)
I changed the keys to address_match
but still see the same (or very similar) error:
TASK [activemq : Create amqp broker connections configuration string] **************************************************************************************************************************************
task path: /home/kherbert/work/ansible-middleware/amq/roles/activemq/tasks/validate_config.yml:118
File lookup using /home/kherbert/work/ansible-middleware/amq/roles/activemq/templates/broker_connections.broker.xml.j2 as file
exception during Jinja2 execution: Traceback (most recent call last):
File "/usr/lib/python3.12/site-packages/ansible/template/__init__.py", line 975, in do_template
t = myenv.from_string(data)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/jinja2/environment.py", line 1105, in from_string
return cls.from_code(self, self.compile(source), gs, None)
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/jinja2/environment.py", line 768, in compile
self.handle_exception(source=source_hint)
File "/usr/lib/python3.12/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<unknown>", line 2, in template
jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got '='
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.12/site-packages/ansible/template/__init__.py", line 873, in _lookup
ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/ansible/plugins/lookup/template.py", line 160, in run
res = templar.template(template_data, preserve_trailing_newlines=True,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/ansible/template/__init__.py", line 764, in template
result = self.do_template(
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/site-packages/ansible/template/__init__.py", line 977, in do_template
raise AnsibleError("template error while templating string: %s. String: %s" % (to_native(e), to_native(data)), orig_exc=e)
ansible.errors.AnsibleError: template error while templating string: expected token 'end of statement block', got '='. String: <amqp-connection uri="{{ broker_connection.uri }}" name="{{ broker_connection.name }}">
{% for operation in broker_connection.operation, wantlist=True) %}
<{{ operation.type }} {% for param in lookup('ansible.builtin.dict', broker_connection.parameters, wantlist=True) %}{{ param.key | replace('_','-') }}="{{ param.value }}" {% endfor %}/>
{% endfor %}
</amqp-connection>. expected token 'end of statement block', got '='
fatal: [192.168.122.141]: FAILED! => {
"msg": "An unhandled exception occurred while running the lookup plugin 'template'. Error was a <class 'ansible.errors.AnsibleError'>, original message: template error while templating string: expected token 'end of statement block', got '='. String: <amqp-connection uri=\"{{ broker_connection.uri }}\" name=\"{{ broker_connection.name }}\">\n{% for operation in broker_connection.operation, wantlist=True) %}\n <{{ operation.type }} {% for param in lookup('ansible.builtin.dict', broker_connection.parameters, wantlist=True) %}{{ param.key | replace('_','-') }}=\"{{ param.value }}\" {% endfor %}/>\n{% endfor %}\n </amqp-connection>. expected token 'end of statement block', got '='. template error while templating string: expected token 'end of statement block', got '='. String: <amqp-connection uri=\"{{ broker_connection.uri }}\" name=\"{{ broker_connection.name }}\">\n{% for operation in broker_connection.operation, wantlist=True) %}\n <{{ operation.type }} {% for param in lookup('ansible.builtin.dict', broker_connection.parameters, wantlist=True) %}{{ param.key | replace('_','-') }}=\"{{ param.value }}\" {% endfor %}/>\n{% endfor %}\n </amqp-connection>. expected token 'end of statement block', got '='"
}
reproduced
Hello I have a PR above addressing this problem; can you test it? (or I can merge it and eventually forward fix)
I pulled and ran the PR branch. It fixed the template error, but now I get this error, it seems for not providing parameters user
and password
when defining the connection:
TASK [activemq : Create amqp broker connections configuration string] *******************************************************************************************************
task path: /home/kherbert/work/ansible-middleware/amq/roles/activemq/tasks/validate_config.yml:118
File lookup using /home/kherbert/work/ansible-middleware/amq/roles/activemq/templates/broker_connections.broker.xml.j2 as file
fatal: [192.168.122.141]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'user'. 'dict object' has no attribute 'user'. 'dict object' has no attribute 'user'. 'dict object' has no attribute 'user'\n\nThe error appears to be in '/home/kherbert/work/ansible-middleware/amq/roles/activemq/tasks/validate_config.yml': line 118, 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: Create amqp broker connections configuration string\n ^ here\n"
}
But from the documentation for that element, I see no mention of providing these credentials. https://access.redhat.com/documentation/en-us/red_hat_amq_broker/7.12/html-single/configuring_amq_broker/index#ref-br-configuring-broker-connections_configuring
I see there's a jinja if-block in roles/activemq/templates/broker_connections.broker.xml.j2
, but I don't see a syntax reason for it to be failing. (But I'm still far from a jinja ninja.)
Unless you setup anonymous access in artemis broker.xml, I think that for sender/receiver user and pass will always be needed (the molecule test was failing on authentication in broker connections); but yeah of course it's not marked required in the xls schema, so i'll add a check for it
Should be fixed, can you please test again?
But I'm still far from a jinja ninja
That, nobody is. The bashfu mastering good'le times are gone :cry:
Looks good on my end. You're right, I need more configuration for it to lack user/password. I can verify that the broker connection exists.
Thank you for the fast turn around on this issue :)
SUMMARY
I try to define a simple bridge between brokerA and brokerB, but get a templating error
ISSUE TYPE
ANSIBLE VERSION
COLLECTION VERSION
STEPS TO REPRODUCE
On a fresh CentOS9 VM, where
admin
is a member ofwheel
group, andbridge
is a host group with just that VM's IP address.EXPECTED RESULTS
A brokered-connection bridge configured between
brokerA
andbrokerB
.ACTUAL RESULTS