Bootstrap FreeKB - Ansible - Increment or Decrement an integer using the int filter
Ansible - Increment or Decrement an integer using the int filter

Updated:   |  Ansible articles

Here is an example of how you can increment an integer using the int filter. In this example, the "count" variable will be incremented by 1.

---
- hosts: localhost
  vars:
    count: 10
  tasks:
  - set_fact:
      count={{ count | int + 1 }}

  - name: print count
    debug:
      var: count
...

 

Running this playbook should return the following, showing that the count variable is now 11.

ok: [localhost] => {
    "count": "11"
}

 

And here is how you would decrement count by 1.

count={{ count | int - 1 }}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 3f20e0 in the box below so that we can be sure you are a human.