store the output of math operator

  • name: Set the output of the this state
    set_fact: A=“{{image_avl.stdout}}” – this is coming from the previous registered output
    tags: avl1

  • name: Define our static value for the desired image number
    set_fact: B={{retain}} – this is coming from the inventory
    tags: num2

  • name: difference
    set_fact: C = {{A}} - {{B}}
    tags: del1

I want to store the value of A -B in C. However, its not storing and showing blank result

solved it.

Well done!

Any chance of sharing *how* you solved it?

Thanks,

  • name: Set the output of the this state
    set_fact: A=“{{image_avl.stdout}}” – this is coming from the previous registered output
    tags: avl1

  • name: Define our static value for the desired image number
    set_fact: B={{retain}} – this is coming from the inventory
    tags: num2

  • name: difference
    shell: C=expr "{{image_avl.stdout}}" - {{retain}}
    register: num_del
    tags: del1

  • debug: var=“num_del”

Invoking the shell module is not necessary. One can use jinja2. An example:

$ cat a.yaml
- hosts: localhost

  tasks:
    - set_fact: A="5"
    - set_fact: B="6"
    - set_fact: C="{{ A|int - B|int }}"
    - debug: var=C

$ ansible-playbook -v a.yaml
No config file found; using defaults
[WARNING]: Host file not found: /etc/ansible/hosts

[WARNING]: provided hosts list is empty, only localhost is available

PLAY [localhost]

Hello from Oklahoma City,

My name is Andreas I noticed your post looking around for something about subtracting two variables but my vars are dates converted to strings but I can’t seem to get the two vars to subtract I started with a bash script.