I am using the when conditional in ansible but it doens't seem to work. If I run the playbook, it never checks with the condition rather it sets the last set_fact value of "shot"
---
- hosts: sandbox
user: robo
become: yes
gather_facts: yes
tasks:
- debug: msg="{{ansible_memtotal_mb}}"
- name: SHOT value for MEM less than 16G
set_fact:
shot: 3670016
when: ansible_memtotal_mb|int <= 16384
- name: SHOT value for MEM is between 16G and 32G
set_fact:
shot: 7340032
when: ansible_memtotal_mb|int > 16384 and ansible_memtotal_mb|int <= 32768
- debug: var=shot
================================================================================
SUDO password:
PLAY [sandbox] *****************************************************************
TASK [setup] *******************************************************************
ok: [uslv-sapp-lnx11]
TASK [debug] *******************************************************************
ok: [uslv-sapp-lnx11] => {
"msg": 7872
}
TASK [SHOT value for MEM less than 16G] **************************************
ok: [uslv-sapp-lnx11]
TASK [SHOT value for MEM is between 16G and 32G] *****************************
ok: [uslv-sapp-lnx11]
TASK [debug] *******************************************************************
ok: [uslv-sapp-lnx11] => {
"shot": 7340032
}
PLAY RECAP *********************************************************************
uslv-sapp-lnx11 : ok=5 changed=0 unreachable=0 failed=0