title: Get output of ansible task in proper readable format like JSON
body: <p>I am trying to read a content of file. Lets say I have a hosts file in <code>/etc/hosts</code>. I want to read the content of the file. When I run ansible playbook it contains several logs containing task name and symbols.</p>
  
  <p>ansible playbook file:</p>
  
  <pre><code>- hosts: all
    remote_user: "{{ ansible_user }}"
    vars:
      ansible_become_pass: "{{ ansible_ssh_pass }}"
  
    tasks:
      - name: Read file
        command: cat /etc/hosts
        register: response
  
      - debug: msg="Content of file is {{ response }}"
  </code></pre>
  
  <p>Logs emitted by ansible:</p>
  
  <pre><code>$ ansible-playbook -i inventory.yml playbook.yml 
  
  PLAY [all] *************************************************************************************************************************************************************************************************
  
  TASK [Gathering Facts] *************************************************************************************************************************************************************************************
  ok: [18.222.139.140]
  
  TASK [Read file] *******************************************************************************************************************************************************************************************
  changed: [18.222.139.140]
  
  TASK [debug] ***********************************************************************************************************************************************************************************************
  ok: [18.222.139.140] =&gt; {
      "msg": "Content of file is {'stderr_lines': [], u'changed': True, u'end': u'2018-10-08 19:21:52.968466', 'failed': False, u'stdout': u'127.0.0.1 localhost\\n\\n# The following lines are desirable for IPv6 capable hosts\\n::1 ip6-localhost ip6-loopback\\nfe00::0 ip6-localnet\\nff00::0 ip6-mcastprefix\\nff02::1 ip6-allnodes\\nff02::2 ip6-allrouters\\nff02::3 ip6-allhosts\\nHii just testing', u'cmd': [u'cat', u'/etc/hosts'], u'rc': 0, u'start': u'2018-10-08 19:21:52.966509', u'stderr': u'', u'delta': u'0:00:00.001957', 'stdout_lines': [u'127.0.0.1 localhost', u'', u'# The following lines are desirable for IPv6 capable hosts', u'::1 ip6-localhost ip6-loopback', u'fe00::0 ip6-localnet', u'ff00::0 ip6-mcastprefix', u'ff02::1 ip6-allnodes', u'ff02::2 ip6-allrouters', u'ff02::3 ip6-allhosts', u'Hii just testing']}"
  }
  
  PLAY RECAP *************************************************************************************************************************************************************************************************
  18.222.139.140             : ok=3    changed=1    unreachable=0    failed=0   
  </code></pre>
  
  <p>The issue is, I just want this output </p>
  
  <pre><code>{
    "msg": "Content of file is {'stderr_lines': [], u'changed': True, u'end': u'2018- 
    10-08 19:21:52.968466', 'failed': False, u'stdout': u'127.0.0.1 localhost\\n\\n# 
    The following lines are desirable for IPv6 capable hosts\\n::1 ip6-localhost ip6- 
    loopback\\nfe00::0 ip6-localnet\\nff00::0 ip6-mcastprefix\\nff02::1 ip6- 
    allnodes\\nff02::2 ip6-allrouters\\nff02::3 ip6-allhosts\\nHii just testing', 
    u'cmd': [u'cat', u'/etc/hosts'], u'rc': 0, u'start': u'2018-10-08 19:21:52.966509', 
    u'stderr': u'', u'delta': u'0:00:00.001957', 'stdout_lines': [u'127.0.0.1 
    localhost', u'', u'# The following lines are desirable for IPv6 capable hosts', 
    u'::1 ip6-localhost ip6-loopback', u'fe00::0 ip6-localnet', u'ff00::0 ip6- 
    mcastprefix', u'ff02::1 ip6-allnodes', u'ff02::2 ip6-allrouters', u'ff02::3 ip6- 
    allhosts', u'Hii just testing']}"
  }
  </code></pre>
  
  <p>or any other output that can be parsed through a program.</p>
  
  <p>Any help/suggestion would be appreciated.</p>
  
  <p>I am using go-lang to invoke <code>ansible-playbook</code> command</p>