Q:

Ansible: Use an integer across different playbooks, increment it on each use

I'm fairly new to ansible.
I need a counter that increments by 1 on each run of any one of multiple playbooks. The counter needs to be stored on the machine running the playbook. I have a way to do this, but it feels long winded. I want to know what best practice should be. 
Here is how I am doing it:
---
- name: increment number
  hosts: 127.0.0.1
  vars:
   request_id: "{{ lookup('file', '/path/counter.txt') }}"
  connection: local
  gather_facts: no

  tasks:
   - debug: msg="request id is: {{ request_id }}"
   - name: increment number in file
     copy: content={{ request_id | int + 1 }} dest=/path/counter.txt

How should I be doing this? Using a fact or something?

A:

There is no simpler way doing this. Since Ansible is stateless you need to store your counter int somewhere, for example a file like you did.
You can use Ansibles fact caching. While that might look cleaner it is more effort to set it up. For fact caching you need to install Redis.

