1

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 Ansible: Save registered variables to file But I want to be able to save the variables as a dictionary

---
- name: Get variable1
  shell: "some java command"
  register: variable1

- name: Get variable2
  shell: "some java command"
  register: variable2

Now, I want to save them to a file in the form of dictionary like

dictionary_variable:
   var1: "{{ variable1 }}"
   var2: "{{ variable2 }}"

I should be able to access the dictionary like

{{ dictionary_variable.var1 }} or {{ dictionary_variable.var2 }} 
user3086551
  • 405
  • 1
  • 4
  • 13
  • You can try one of the filters [in here](http://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data). I recommend using `{{ var | to_nice_json }}` in your `local_action` task. I say this, because a _json_ file is practically a file with a dictionary inside. – David May 22 '18 at 09:00

0 Answers0