Ansible - Subtraction

by
Jeremy Canfield |
Updated: October 05 2023
| Ansible articles
Here is a simple example of how you can perform subtraction in Ansible.
---
- hosts: localhost
tasks:
- name: subtraction example
set_fact:
result: "{{ 5 - 1 }}"
- debug:
var: result
...
Which should return the following.
ok: [localhost] => {
"result": "4"
}
Likewise, you should be able to work with decimal point numbers and variables, perhaps something like this.
---
- hosts: localhost
vars:
mynumber: 5.75
tasks:
- name: subtraction example
set_fact:
result: "{{ mynumber - 1.25 }}"
- debug:
var: result
...
Did you find this article helpful?
If so, consider buying me a coffee over at