title: Ansible: Efficient way of defining "vars" in multiple plays/tasks?
body: <p>Ansible: Efficient way of defining &quot;vars&quot; in multiple plays/tasks</p>
  <p>We have got 100's of playbooks, tasks etc. In many of the tasks, we need to extract a unique var &amp; based on thhat set of another &quot;vars&quot; from a lookup. This is mainly for meta-information and append to template. But every time I have to put vars, we need to put them one by one in the task. Is there a better/efficient way to make the &quot;vars&quot; itself like a template? So I can just use a template and fill up all the vars?</p>
  <p>Please find an example</p>
  <pre><code>- name: &quot;play1, task1&quot;
    file:
      something..
    loop: my_dict1
    vars:
      empID: {{item|someSplitting|anothercalculation}}
      empFirstName: {{empID|some_filter}}
      ... set_of_20_vars_based_on_empID_lookup
  
  - name: &quot;a separate play/task&quot;
    &lt;another_activity&gt;:
      something..
    loop: another_dict_to_stitch_together_to_my_dict1
    vars:
      somethingDifferent: {{item|someCalculation}}
      empID: {{somethingDifferent|someSplitting|anothercalculation}}
      empFirstName: {{empID|some_filter}}
      ... set_of_20_vars_based_on_empID_lookup repeated
  </code></pre>
  <p>So I was looking for an option in the vars, where I can define ALL those 20+ vars into a single place, so I can just re-use it?
  something like below..</p>
  <pre><code>- name: &quot;Any task&quot;
    template:
      &lt;fill_my_template_with_vars&gt;
    loop: my_any_dict_or_list
    vars:
      somethingDifferent2: {{item|someCalculation}}
      empID: {{somethingDifferent2|someSplitting|anothercalculation}}
      my_employee_vars: {{import_List_of_all_standard_20vars_lookup}}
  </code></pre>
  <p>Any help would be appreciated</p>