title: How to write a dictionary variable to the file in Ansible?
body: <p>I am trying to save a set of the registered variables as a dictionary to a file.
  I can find the solution to save multiple variables to a file here
  <a href="https://stackoverflow.com/questions/42942408/ansible-save-registered-variables-to-file?rq=1">Ansible: Save registered variables to file</a>
  But I want to be able to save the variables as a dictionary</p>
  
  <pre><code>---
  - name: Get variable1
    shell: "some java command"
    register: variable1
  
  - name: Get variable2
    shell: "some java command"
    register: variable2
  </code></pre>
  
  <p>Now, I want to save them to a file in the form of dictionary like</p>
  
  <pre><code>dictionary_variable:
     var1: "{{ variable1 }}"
     var2: "{{ variable2 }}"
  </code></pre>
  
  <p>I should be able to access the dictionary like</p>
  
  <pre><code>{{ dictionary_variable.var1 }} or {{ dictionary_variable.var2 }} 
  </code></pre>