# Modifying local files while targeting a remote system

**URL:** <https://forum.ansible.com/t/modifying-local-files-while-targeting-a-remote-system/25951>\
**Category:** Ansible Project\
**Created:** [November 7, 2017, 7:12pm UTC](https://forum.ansible.com/t/modifying-local-files-while-targeting-a-remote-system/25951 "2017-11-07T19:12:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [November 7, 2017, 7:12pm UTC](https://forum.ansible.com/t/modifying-local-files-while-targeting-a-remote-system/25951/1 "2017-11-07T19:12:59Z")

</div>

Is it possible to modify local files while targeting a remote system in an Ansible YAML file? I’m trying to run an Ansible script on a remote machine, but when everything finishes on that remote machine, I’d like to move that hostname from one Ansible hosts file to another. Is it possible and if so, could someone point me in the right direction? Thanks!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 7, 2017, 7:19pm UTC](https://forum.ansible.com/t/modifying-local-files-while-targeting-a-remote-system/25951/2 "2017-11-07T19:19:21Z")

</div>

On all task you can use delegate\_to[1] and that task will run on the delegated machine.  
So "delegate\_to: localhost" will run on local machine and not on the remote host.

To change a file you have the lineinfile module or the template module.

[1] [https://docs.ansible.com/ansible/latest/playbooks\_delegation.html#delegation](https://docs.ansible.com/ansible/latest/playbooks_delegation.html#delegation)

---

<div class="post-metadata">

**Author:** ![EspressoBeanies](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@EspressoBeanies](https://forum.ansible.com/u/EspressoBeanies)\
**Post date:** [November 7, 2017, 10:23pm UTC](https://forum.ansible.com/t/modifying-local-files-while-targeting-a-remote-system/25951/3 "2017-11-07T22:23:22Z")

</div>

Thanks Kai
