title: How to use a dictionary of registered ansible variables in vars?
body: <p>I want to pass multiple variables to a task using <code>vars</code>. Currently, I am doing it like below</p>
  
  <pre><code>vars:
      var1_name: "var1_value"
      var2_name: "var2_value"
  </code></pre>
  
  <p>As the number of variables can grow in size, I'd rather prefer to pass the dictionary of variables to the task using <code>vars</code>. I have constructed a dictionary of variables like below</p>
  
  <pre><code>- name: set fact
    hosts: localhost
    tasks:
    - set_fact:
        variables: "{{ variables|default({}) | combine( {item.variable: item.value} ) }}"
      with_items:
      - variable: var1_name
        value: "var1_value"
      - variable: var2_name
        value: "var2_name"
  </code></pre>
  
  <p>Dictionary looks something like this:</p>
  
  <pre><code>"variables": {
      "var1_name": "var1_value",
      "var2_name": "var2_value",
  }
  </code></pre>
  
  <p>Now, I want to make variables in this dictionary available to roles executing on other hosts.</p>
  
  <p>But, when I tried to pass dictionary to <code>vars</code> like below </p>
  
  <pre><code>vars: "{{ variables }}"
  </code></pre>
  
  <p>Ansible throws the error:</p>
  
  <pre><code>ERROR! Vars in a Play must be specified as a dictionary, or a list of dictionaries
  </code></pre>
  
  <p>How to pass a dictionary variable in <code>vars</code>?</p>