What is the difference between Ansible template module and copy module?

What is the difference between Ansible template module and Ansible copy module?

+7
ansible
source share
1 answer

While very similar, the template serves as an extra feature.

  • copy takes the file from the host,
    "as-is",
    and copies it to the remote destination.
  • template accepts a file (template) from the host,
    changes variables based on Jinja2 filtering,
    and copies it to the remote destination.

You can use the template to copy the file without formatting the template from the host to the remote destination.

An example of a template copy template is when you need to import a custom configuration file based on parameters from the host (or elsewhere), for example, a web configuration file that accepts host / credential properties from a database instance. Please note that this could be done using copy / lineinfile - this is just another way to do this.

+12
source share

All Articles