use ansible module copy instead of template for small files
In order to adapt files and their content on target servers I am used to using ansible copy module. However, if you only have a small file with just one or a few lines, you can do so without creating a jinja2 template.
Here is the little cheat: Just use ansible’s copy module.
YAML
- name: Adjust content of file
ansible.builtin.copy:
content: "homedir: {{ lookup('ansible.builtin.env', 'HOME')"
dest: /app/env.ymlThat’s it. This creates a file with variable content, without need to create a template.