I am starting to use Ansible in order to write a playbook that will deploy a staging environment for our application. I'm trying to understand if the best practice for applying changes to files are to change them locally on the control machine and then propagate them into the remote server, or whether the files should be manipulated inside the playbook.
Manipulating the files through the playbook seems better in terms of readability and documentation, as well as keeping the entire configuration process to one tool for the entire configuration process. On the other hand, changing the files on the local server is easier and faster.
What is the best way to approach these problems?
Thanks, Yaron.
Welcome to Ansible!
I think you should have a look at Templates. Never change Files locally and deploy them. Your deployment should not change any file locally!
If you have a config file, write a template for this file and render some variables inside to change the config for the deployed application. The template module will render the file directly to your server.
Use lineinfile
and blockinfile (ansible > 2.0)
. It is cleaner, portable and can be run from any control machine. But there are exception when the block is huge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With