You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Managing configuration files is one of the most common tasks in infrastructure automation. Ansible provides the template module (powered by Jinja2) for dynamic files and the copy module for static files.
| Feature | copy Module | template Module |
|---|---|---|
| Source | Static file | Jinja2 template (.j2) |
| Variables | Not supported | Fully supported |
| Logic | None | Conditionals, loops, filters |
| Use case | Files that never change | Configuration files that vary per host or environment |
Copy static files from the control node to managed nodes:
tasks:
- name: Copy static HTML file
copy:
src: files/index.html
dest: /var/www/html/index.html
owner: www-data
group: www-data
mode: '0644'
- name: Copy with backup
copy:
src: files/app.conf
dest: /etc/app/app.conf
backup: true # Create a backup of the existing file
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.