# changed\_when: NumberA \> NumberB

**URL:** <https://forum.ansible.com/t/changed-when-numbera-numberb/19608>\
**Category:** Ansible Project\
**Created:** [October 25, 2015, 7:27am UTC](https://forum.ansible.com/t/changed-when-numbera-numberb/19608 "2015-10-25T07:27:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [October 25, 2015, 7:27am UTC](https://forum.ansible.com/t/changed-when-numbera-numberb/19608/1 "2015-10-25T07:27:29Z")

</div>

I’m attempting to compare version numbers of a app by extracting the current version from the output of a shell command and comparing it to the version to be deployed. However the result of the changed\_when: evaluation is always true, regardless of the numbers I put in. I’ve confirmed the numbers that it’s evaluating through debug: msg tasks. Is there a way to make this work?

Here’s a simplified version:

```auto

- hosts: all
  vars:
    NEW_VERSION: 2
  tasks:
  - name: weblogic patch downgrade check 
    shell: "echo '2'"
    register: current_version 
    changed_when: current_version.stdout > {{ NEW_VERSION }}

```

```auto
The actual task syntax i'm using

```

```auto

- name: weblogic patch downgrade check 
  shell: "cat /app/psoft/logs/wlversion |sed -n -e 's/^Patch \([0-9]\{8\}\).*/\1/p'"
  register: old_patch_version 
  changed_when: old_patch_version.stdout > {{ WEBLOGIC_PATCH }}

In this example, both old_patch_version.stdout and {{ WEBLOGIC_PATCH }} are returning 20844228 but the task is registering as changed: true.

```

```auto
Thanks!

```

---

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [October 25, 2015, 5:19pm UTC](https://forum.ansible.com/t/changed-when-numbera-numberb/19608/2 "2015-10-25T17:19:51Z")

</div>

I came across this link which pretty much explains what my problem is. These are strings i’m trying to do mathematical compares against. I’d need a way to convert them to int’ss to do a comparison like this. If anyone has any ideas, please let me know.

[https://github.com/ansible/ansible/issues/8498](https://github.com/ansible/ansible/issues/8498)

---

<div class="post-metadata">

**Author:** ![Jason3](https://avatars.discourse-cdn.com/v4/letter/j/f9ae1b/32.png) [@Jason3](https://forum.ansible.com/u/Jason3)\
**Post date:** [October 25, 2015, 6:50pm UTC](https://forum.ansible.com/t/changed-when-numbera-numberb/19608/3 "2015-10-25T18:50:41Z")

</div>

I found the answer. By putting | int }} next to the variable, it converts to an integer and compares properly.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 26, 2015, 1:42pm UTC](https://forum.ansible.com/t/changed-when-numbera-numberb/19608/4 "2015-10-26T13:42:59Z")

</div>

first thing you don't need the extra moustaches:

changed\_when: current\_version.stdout \> NEW\_VERSION

yes, int will 'fix' the comparison

changed\_when: current\_version.stdout|int \> NEW\_VERSION|int

but this will only work for major versions 2.1 vs 3.2 and not minor  
2.1 vs 2.2, what you reall want is:

changed\_when: current\_version.stdout | version\_compare(NEW\_VERSION,  
operator='gt')
