ansible,  DevOps

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.yml

That’s it. This creates a file with variable content, without need to create a template.

Leave a Reply

Your email address will not be published. Required fields are marked *