Latest release (2.19.0) breaks task

I have a Playbook who install a new Software version if a new version is available. With the version ansible [core 2.14.18] (Debian Bookworm) it works, but I I use the same Playbook with ansible [core 2.19.0b6] (Debian Trixie) I get an error when I compare two registers

# get latest software version installed
- name: get latest software version installed
  shell:
    cmd: "Command to get latest version installed"
  register: software_version_installed

- debug:
    msg: latest software version installed is v{{ software_version_installed.stdout }}

# get latest software version to install
- name: get latest software version to install
  shell:
    cmd: "Command to get latest version on Github"
  register: software_version_to_install

- debug:
    msg: latest software version to install is v{{ software_version_to_install.stdout }}


# exit if latest software version is installed
- name: exit if latest software version v{{ software_version_to_install.stdout }} is installed
  fail:
    msg:
      "latest software version v{{ software_version_installed.stdout }} is installed"
  when: software_version_installed.stdout | length > 0 and software_version_to_install.stdout is version(software_version_installed.stdout, '==')

The error I get is

TASK [software : get latest software version installed] **********************************************************************************************
changed: [server1]

TASK [software : debug] *************************************************************************************************************************
ok: [server1] => {
    "msg": "latest software version installed is v1.0"
}

TASK [software : get latest software version to install] *********************************************************************************************
changed: [server1]

TASK [software : debug] *************************************************************************************************************************
ok: [server1] => {
    "msg": "latest software version to install is v1.0"
}

TASK [software : exit if latest software version v1.0 is installed] ******************************************************************************
[ERROR]: Task failed: Action failed: latest software version v1.0 is installed
Origin: /home/wim/playbooks/roles/software/tasks/main.yml:23:3

21
22 # exit if latest software version is installed
23 - name: exit if latest software version v{{ software_version_to_install.stdout }} is installed
     ^ column 3

fatal: [server1]: FAILED! => {"changed": false, "msg": "latest software version v1.0 is installed"}

  • Set at least one tag (the experts follow the tags, so the right people will find you if you tag)

See A quick guide to templating changes for general help on core 2.19 and understanding the templating changes in that release.

2 Likes

You’re asking the playbook to fail if the versions are equal, and that’s what it does. (“fail” produces an error if it succeeds: ansible.builtin.fail module – Fail with custom message — Ansible Core Documentation)

What exactly are you expecting? A less “error”-like behavior if ansible.builtin.fail is invoked?

2 Likes

Thanks for your quick reply

With ansible [core 2.14.18] I get this message and then it quit the playbook like I expected.

TASK [zed : exit if latest zed version v1.0 is installed] ******************************************************************************
fatal: [wegc203063]: FAILED! => {"changed": false, "msg": "latest zed version v1.0 is installed"}

It’s the same error, it just contains extra context information about where the error came from.

Now it looks like a fatal error, an it shouldn’t be an error. Just quit the playbook with a message if the latest version is installed.
Is there another way to do it more clear?
Many thanks.

- name: Stop playbook
  when: old.version == new.version
  block:
    - name: Show that the versions are the same
      ansible.builtin.debug:
        msg: The versions are the same

    - name: Stop this host
      ansible.builtin.meta: end_host

Many thanks!!
That’s a much nicer way to end the playbook :grinning_face: