title: Ansible playbook-wide variable
body: <p>I have a playbook with multiple hosts section. I would like to define a variable in this playbook.yml file that applies only within the file, for example:</p>
  
  <pre><code>vars:
    my_global_var: 'hello'
  
  - hosts: db
    tasks:
     -shell: echo {{my_global_var}} 
  
  - hosts: web
    tasks:
     -shell: echo {{my_global_var}} 
  </code></pre>
  
  <p>The example above does not work. I have to either duplicate the variable for each host section (bad) or define it at higher level, for example in my <code>group_vars/all</code> (not what I want, but works). I am also aware that variables files can be included, but this affects readibility. Any suggestion to get it in the right scope (e.g the playbook file itself)?</p>