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

34 views
Skip to first unread message

shyam...@gmail.com

unread,
Mar 4, 2019, 2:49:50 AM3/4/19
to Ansible Project
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:

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

shyam...@gmail.com

unread,
Mar 4, 2019, 3:11:56 AM3/4/19
to Ansible Project
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

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


Thanks and Regards,
Shyam.
    
      


Kai Stian Olstad

unread,
Mar 4, 2019, 6:10:41 AM3/4/19
to ansible...@googlegroups.com
On 04.03.2019 09:11, shyam...@gmail.com wrote:
> 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

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages