DevOps / Ansible Interview questions
What is the difference between copy and template modules?
| copy | template |
| Transfers a file as-is, byte for byte. | Renders a Jinja2 template file before transferring it. |
| Good for static files that never change per host. | Good for config files that need per-host or per-environment values inserted. |
| No templating syntax processed in the source file. | Supports variables, conditionals, and loops via Jinja2 syntax. |
- name: Static file, unchanged everywhere ansible.builtin.copy: src: files/motd dest: /etc/motd - name: Config that varies per host ansible.builtin.template: src: templates/app.conf.j2 dest: /etc/app/app.conf
Use copy for content that's identical across every target, like a license file or a static binary. Use template whenever the destination file needs to embed values that differ by host or environment, such as a database hostname, port number, or feature flag, since Jinja2 templating ({{ variable }}, {% if %}, {% for %}) inside a .j2 file is only processed by the template module, not copy.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
