Template replacement

Have a template which updates the host name of an webserver configuration file .
I'm good here , the host gets updated properly. I use the template src tag to do this.

After this task ,the deployment task runs for the application which puts an entry into the webserver configuration file .

When I rerun the playbook , the template task notifies as changed since , on the server it was updated in the last run.It thus again copies the template again , which overwrites the deployment entry done last run.

How can tell Ansible ignore extra changes on the file from webserver deployment persoective, but still get changes from template if anything extra added in ansible source

Do not use the template module, as it changes the whole file. If you
just have to change one value, use the lineinfile module to change one
line in the file.

https://docs.ansible.com/ansible/lineinfile_module.html

I think there is no way to get the behaviour you describe, I could
only imagine creating a bash script or similar that compares the two
files and ignores your later deployment changes. But that feels like a
hack...

Johannes