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

While very similar, template serves an extra function.

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

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

An example of copy over template is when you need to import a custom config file based on parameters from the host (or elsewhere), such as a web config file that takes host/credential properties from a database instance. Note the same could be achieved by using copy/lineinfile--this is just a different way of doing so.

Tags:

Ansible