title: Ansible increment variable globally for all hosts
body: <p>I have two servers in my inventory (hosts)</p>
  
  <pre><code>[server]
  10.23.12.33
  10.23.12.40
  </code></pre>
  
  <p>and playbook (play.yml)</p>
  
  <pre><code>---
  - hosts: all
    roles:
      web
  </code></pre>
  
  <p>Inside web role in vars directory i have main.yml</p>
  
  <pre><code>---
  file_number : 0
  </code></pre>
  
  <p>Inside web role in tasks directory i have main.yml</p>
  
  <pre><code>---
  - name: Increment variable
    set_fact: file_number={{ file_number | int + 1 }}
  
  - name: create file
    command: 'touch file{{ file_number }}'
  </code></pre>
  
  <p>Now i expect that in first machine i will have <strong>file1</strong> and in second machine i will have <strong>file2</strong> but in both machines i have <strong>file1</strong></p>
  
  <p>So this variable is local for every machine, how could i make it global for all machines.</p>
  
  <p>My file structure is:</p>
  
  <pre><code>hosts
  play.yml
  roles/
    web/
      tasks/
        main.yml
      vars/
        main.yml
  </code></pre>