Inexplicable element when a sentence raises an error: cannot find a name or access an attribute in a template line

In the next task, I get an 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 traced it to the suggestion when.

Using debug statements, I confirmed:

  • mysql_server_version='5.2.23'
  • mysql_client_version='5.2.23'
  • mysql_version='5.2.23'

If I delete the statement when, the task starts.

 - 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"

Version

  • ansible 1.9.0.1
+5
source share
1 answer

According to the documents, conditions whenshould not use template markers {{and }}, as they are already implied.

Try this instead:

when: mysql_server_version | version_compare(mysql_version, '<') or 
      mysql_client_version | version_compare(mysql_version, '<')
0
source

All Articles