Reputation: 30025
I need to create or overwrite files on remote hosts. The modules lineinfile
or blockinfile
are useful when updating files, but not to create ones from scratch or completely overwrite existing ones.
The obvious solution is to use copy
but I would like to have as much as possible a standalone playbook, without files on the side. Is it possible to include in a playbook the content of the file to create?
Maybe something along the lines of having a variable with the content of the file which can be used as the src=
parameter for copy
(I tried this but it does not work as src
expects a local file)
Upvotes: 23
Views: 29716
Reputation: 68289
Copy with content:
tasks:
- copy:
content: |
This is some
not too complex
cotent for a file
dest: content.txt
But as per Ansible doc:
This is for simple values, for anything complex or with formatting please switch to the template module.
Upvotes: 57