Write variable to a file in Ansible

Keith Adler picture Keith Adler · Oct 29, 2014 · Viewed 143.4k times · Source

I am pulling JSON via the URI module and want to write the received content out to a file. I am able to get the content and output it to the debugger so I know the content has been received, but I do not know the best practice for writing files.

Answer

Ramon de la Fuente picture Ramon de la Fuente · Oct 29, 2014

You could use the copy module, with the content parameter:

- copy: content="{{ your_json_feed }}" dest=/path/to/destination/file

The docs here: copy module