title: Ansible append dict results for all hosts
body: <p>I am attempting to use Ansible to send a command to several hosts that returns a dict.  I then want to append the the dict results of each host to accumulate the results of all the hosts. Finally, I want to print the dict of accumulated results for later processing or to write to a file. It appears I am failing to combine the dicts due to results showing as string. Is there a way to remedy this? Also, is there a more Ansible efficient way to accomplish this?</p>
  
  <p><strong>Example Playbook:</strong></p>
  
  <pre><code>---
    - hosts: myhosts
      gather_facts: False
      vars:
        mydict: {}
      tasks:
      - name: Get dict result
        shell: "cat /path/dict_output"
        register: output
      - set_fact:
         result_dict="{{ output.stdout}}"
  
      - debug: var=result_dict
  </code></pre>
  
  <p><strong>Debug Output:</strong></p>
  
  <pre><code>TASK [debug] ****************************************************************************************************************************************************************
  ok: [host-a] =&gt; {
      "result_dict": {
          "host_b": [
              {
                  "ip-1": {
                      "port": "22", 
                      "service": "ssh"
                  }
              }, 
              {
                  "ip-2": {
                      "port": "21", 
                      "service": "ftp"
                  }
              }
          ]
      }
  }
  ok: [host-b] =&gt; {
      "result_dict": {
          "host_a": [
              {
                  "ip-1": {
                      "port": "22", 
                      "service": "ssh"
                  }
              }, 
              {
                  "ip-2": {
                      "port": "21", 
                      "service": "ftp"
                  }
              }
          ]
      }
  }
  </code></pre>
  
  <p><strong>My Attempt to combine results of each host:</strong></p>
  
  <pre><code>- set_fact:
     mydict: "{{ mydict | combine(output.stdout) }}"
  - debug: var=mydict
  </code></pre>
  
  <p>Failed Result:</p>
  
  <pre><code>TASK [set_fact] *************************************************************************************************************************************************************
      fatal: [host-b]: FAILED! =&gt; {"msg": "|combine expects dictionaries, got u\"{'host_b': [{'ip-1': {'service': 'ssh', 'port': '22'}}, {'ip-2': {'service': 'ftp', 'port': '21'}}]}\""}
      fatal: [host-a]: FAILED! =&gt; {"msg": "|combine expects dictionaries, got u\"{'host_a': [{'ip-1': {'service': 'ssh', 'port': '22'}}, {'ip-2': {'service': 'ftp', 'port': '21'}}]}\""}
  </code></pre>
  
  <p><strong>Desired output of accumulated results:</strong></p>
  
  <pre><code>{'host_a': [{'ip-1': {'port': '22', 'service': 'ssh'}},
              {'ip-2': {'port': '21', 'service': 'ftp'}}],
   'host_b': [{'ip-1': {'port': '22', 'service': 'ssh'}},
              {'ip-2': {'port': '21', 'service': 'ftp'}}]}
  </code></pre>