title: How to write varibles/hard code values in nested json in ansible?
body: <p>I'm trying to create a json file with hard codes valuesas a output in nested json.But the second play is overwriting the first play value.So do we have any best option to do this?</p>
  
  <p>I have tried with to_nice_json template to copy the variable to json file.But not able to keep multiple variable values in imported_var to copy to json file</p>
  
  <pre><code>---
  - hosts: localhost
    connection: local
    gather_facts: false
  
    tasks:
    - name: load var from file
      include_vars:
        file: /tmp/var.json
        name: imported_var
  
    - name: Checking mysqld status
      shell: service mysqld status
      register: mysqld_stat
      ignore_errors: true
  
    - name: Checking mysqld status
      shell: service httpd status
      register: httpd_stat
      ignore_errors: true
  
    - name: append mysqld status to output json
      set_fact:
       imported_var: "{{ imported_var | combine({ 'status_checks':[{'mysqld_status': (mysqld_stat.rc == 0)|ternary('good', 'bad') }]})}}"
  
  # - name: write var to file
   #   copy:
    #    content: "{{ imported_var | to_nice_json }}"
     #   dest: /tmp/final.json
  
    - name: append httpd status to output json
      set_fact:
        imported_var: "{{ imported_var| combine({ 'status_checks':[{'httpd_status': (httpd_stat.rc == 0)|ternary('good', 'bad') }]})}}"
  
   # - debug:
    #    var: imported_var
  
    - name: write var to file
      copy:
        content: "{{ imported_var | to_nice_json }}"
        dest: /tmp/final.json
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>{
      "status_checks": [
          {
              "mysqld_status": "good"
              "httpd_status": "good"
          }
      ]
  }
  </code></pre>
  
  <p>Actual result:</p>
  
  <pre><code>{
      "status_checks": [
          {
              "httpd_status": "good"
          }
      ]
  }
  </code></pre>