I have implemented a mechanism, which helps us to check version on our gitlab system before running any upgrade.
Which worked fine as long I was running from a local Ansible Controller.
At the moment I migrate to AWX including a version upgrade on our ansible setup.
local old version: ansible [core 2.18.6]
new version on AWX EE: ansible [core 2.20.0]
Since it will be hard to provide a real MWE I try to show the code and the output I got on AWX and the expected on local controller.
The Playbook:
- name: Prerun CHECKS
hosts: gitlab
tags: CHECKS
gather_facts: false
vars:
gitlab_product: ee
gitlab_expected_current_version: 18.5.1
gitlab_target_version: 18.5.1
gitlab_expected_current_version_full: "{{ gitlab_expected_current_version }}-{{ gitlab_product }}.0"
gitlab_target_version_full: "{{ gitlab_target_version }}-{{ gitlab_product }}.0"
tasks:
- name: Get current and latest gitlab version
ansible.builtin.command: apt-cache policy gitlab-{{ gitlab_product }}
register: package_info
changed_when: false
- name: Set current version installed var
ansible.builtin.set_fact:
gitlab_current_version_full: "{{ package_info.stdout |
regex_search('Installed:\\s(\\S+)') |
regex_replace('Installed:\\s', '') |
string }}"
- name: Debug types of versions
ansible.builtin.debug:
msg: |
"gitlab_current_version_full: {{ gitlab_current_version_full | type_debug }}"
"gitlab_expected_current_version_full: {{ gitlab_expected_current_version_full | type_debug }}"
- name: Compare current vs expected version
ansible.builtin.assert:
that:
- "gitlab_current_version_full is version(gitlab_expected_current_version_full, '==')"
fail_msg:
- "{{ gitlab_current_version_full }} and {{ gitlab_expected_current_version_full }}"
- "should be equal!"
success_msg: "Expected Version is equal to installed version."
Since Our gitlab version is already on 18.6.0 I expect Compare current vs expected version to fail what it does on the local controller:
PLAY [Prerun CHECKS] **************************************************************************************************
TASK [Get current and latest gitlab version] **************************************************************************
ok: [gitlab.fb10.fh-dortmund.de]
TASK [Set current version installed var] ******************************************************************************
ok: [gitlab.fb10.fh-dortmund.de]
TASK [Set the latest available version var] ***************************************************************************
ok: [gitlab.fb10.fh-dortmund.de]
TASK [Debug types of versions] ****************************************************************************************
ok: [gitlab.fb10.fh-dortmund.de] => {
"msg": "\"gitlab_current_version_full: NativeJinjaUnsafeText\"\n\"gitlab_expected_current_version_full: str\"\n\"gitlab_latest_version_full: NativeJinjaUnsafeText\"\n\"gitlab_target_version_full: str\" \n"
}
TASK [Compare current vs expected version] ****************************************************************************
fatal: [gitlab.fb10.fh-dortmund.de]: FAILED! => {
"assertion": "gitlab_current_version_full is version(gitlab_expected_current_version_full, '==')",
"changed": false,
"evaluated_to": false,
"msg": [
"18.6.0-ee.0 and 18.5.1-ee.0",
"should be equal!"
]
}
PLAY RECAP ************************************************************************************************************
gitlab.fb10.fh-dortmund.de : ok=7 changed=0 unreachable=0 failed=1 skipped=1 rescued=0 ignored=0
There are a few more outputs in the debug since I checked a few more values.
On AWX I get in check mode following result for the comparison:
PLAY [Prerun CHECKS] ***********************************************************
TASK [Get current and latest gitlab version] ***********************************
skipping: [gitlab.fb10.fh-dortmund.de]
TASK [Set current version installed var] ***************************************
ok: [gitlab.fb10.fh-dortmund.de]
TASK [Set the latest available version var] ************************************
ok: [gitlab.fb10.fh-dortmund.de]
TASK [Debug types of versions] *************************************************
ok: [gitlab.fb10.fh-dortmund.de] => {
"msg": "\"gitlab_current_version_full: str\"\n\"gitlab_expected_current_version_full: str\"\n\"gitlab_latest_version_full: str\"\n\"gitlab_target_version_full: str\"\n\"DIRECT: UndefinedMarker\" \n"
}
TASK [Compare current vs expected version] *************************************
[ERROR]: Task failed: The test plugin 'ansible.builtin.version' failed: Version comparison failed: '<' not supported between instances of 'str' and 'int'
Task failed.
Origin: /runner/project/pb_gitlab_upgrade.yml:64:7
62 "DIRECT: {{ version(gitlab_expected_current_version_full, '==') | type_debug }}"
63
64 - name: Compare current vs expected version
^ column 7
<<< caused by >>>
The test plugin 'ansible.builtin.version' failed.
Origin: /runner/project/pb_gitlab_upgrade.yml:67:13
65 ansible.builtin.assert:
66 that:
67 - "gitlab_current_version_full is version(gitlab_expected_current_version_full, '==')"
^ column 13
<<< caused by >>>
Version comparison failed: '<' not su…
PLAY RECAP *********************************************************************gitlab.fb10.fh-dortmund.de : ok=6 changed=0 unreachable=0 failed=1 skipped=2 rescued=0 ignored=0
I don’t understand why it fails here with the type mismatch. The Debug shows on AWX that both variables are of type str. I don’t see any reference for int in this case. Further the type on the local controller is NativeJinjaUnsafeText which I first expected to create the mismatch situation.
Am I doing something wrong or is this a Bug?