Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ansible

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

like image 928
Docgyan Avatar asked Jun 07 '16 09:06

Docgyan


1 Answers

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.

like image 77
Theo Avatar answered Oct 21 '22 11:10

Theo