In the following task, I am getting the error message Unable to look up a name or access an attribute in template string. Make sure your variable name does not contain invalid characters like '-'.
I have traced it down to the when
clause.
Using debug statements I have verified:
mysql_server_version='5.2.23'
mysql_client_version='5.2.23'
mysql_version='5.2.23'
If I remove the when
statement, the task runs.
- name: download MySQL packages
tags:
- preosupdates
when: "{{ mysql_server_version | version_compare(mysql_version, '<') or mysql_client_version | version_compare(mysql_version, '<') }}"
command: yum update -y --downloadonly MySQL-server-advanced-{{ mysql_version }} MySQL-shared-compat-advanced-{{ mysql_version }} MySQL-client-advanced-{{ mysql_version }}
register: downloadonly
failed_when: downloadonly.rc not in (1, 0)
changed_when: "downloadonly is defined and 'No Packages marked for Update' not in downloadonly.stdout"
According to the docs, when
conditions do not need to use the template markers {{
and }}
since those are already implied.
Try this instead:
when: mysql_server_version | version_compare(mysql_version, '<') or
mysql_client_version | version_compare(mysql_version, '<')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With