Can I include the contents of a file in a playbook?

I need to create or overwrite files on remote hosts. The lineinfile or blockinfile are useful when updating files, but do not create them from scratch or completely overwrite existing ones.

The obvious solution is to use copy , but I would like to have as much stand-alone play as possible, without the files on the side. Can I include the contents of a file in a playbook to create?

Maybe something similar to a variable with the contents of the file, which can be used as the src= parameter for copy (I tried this, but it does not work, since src expects a local file)

+5
source share
2 answers

Copy with content:

  tasks: - copy: content: | This is some not too complex cotent for a file dest: content.txt 

But like Ansible doc :

This is for simple values, for something complicated or with formatting, please switch to the template module.

+17
source

The template module is a good way to achieve your goal.

+2
source

All Articles