How to save the O/P of ansible playbook into a file in windows enviroment

Hi All,

I have a playbook, using REST API getting the details of a process in JSON format. I want to save that JSON o/p to a file in windows environment. Can any one please help me.

sample playbook:

Hi,

I tried the following, im saving the output to a file and trying that to copy to a file. but not working can any one help.

Hi,

I tried the following, im saving the output to a file and trying that to
copy to a file. but not working can any one help.

---
- hosts: windows
  remote_user: admin
  tasks:
  - name: rest api
    win_uri:
      url: http://example.com
      method: GET
      register: json_ouput

Your register is indented to far, it must be on the same level as name and win_uri.

  - name: copying the content to a file
    copy: content="{{ json_ooutput}}" dest=/path/to/destination/file_name

copy is for linux, win_copy is for Windows.

And if you check the documentation under return values for win_uri
https://docs.ansible.com/ansible/2.4/win_uri_module.html#return-values
you see that the output will be in json_ouput.content or json_ouput.json depending on the use of the module and the return of the server.

You can always use this to see the content.

- debug: var=json_ouput