# lineinfile path local and remote path

**URL:** <https://forum.ansible.com/t/lineinfile-path-local-and-remote-path/29823>\
**Category:** Ansible Project\
**Created:** [March 5, 2019, 2:44am UTC](https://forum.ansible.com/t/lineinfile-path-local-and-remote-path/29823 "2019-03-05T02:44:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan1](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Ryan1](https://forum.ansible.com/u/Ryan1)\
**Post date:** [March 5, 2019, 2:44am UTC](https://forum.ansible.com/t/lineinfile-path-local-and-remote-path/29823/1 "2019-03-05T02:44:43Z")

</div>

I have a playbook that uses the following:

- set\_fact: logfile=/home/sandbox/playbooks/LOGS/{{ systemSN }}

Lower in the playbook I have:

- lineinfile:

line: “{{ item }}”  
path: “{{ logfile }}”  
create: yes  
with\_items:

- “Serial Number: {{ ansible\_product\_version }}”

When I run the playbook on Server 1 which has Ansible 2.3.1.0 I get the file created on the local server I am running Ansible from. This is what I want. When I run this same playbook on a different server (“Server 2” on a different network) with Ansible 2.7.8, the file is created on the remote system, which I do not want. Why is the behavior not consistent, and how do I specify that I want the file to be created on the local server I am running Ansible from, not on the remote systems?

---

<div class="post-metadata">

**Author:** ![Ryan1](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Ryan1](https://forum.ansible.com/u/Ryan1)\
**Post date:** [March 5, 2019, 7:07pm UTC](https://forum.ansible.com/t/lineinfile-path-local-and-remote-path/29823/2 "2019-03-05T19:07:42Z")

</div>

It seems this is working. Is this the correct use of delegate\_to?

- lineinfile:

line: “{{ item }}”  
path: “{{ logfile }}”  
create: yes  
delegate\_to: 127.0.0.1  
with\_items:

- “Serial Number: {{ ansible\_product\_version }}”

---

<div class="post-metadata">

**Author:** ![Vino\_Thiyagu](https://avatars.discourse-cdn.com/v4/letter/v/5f9b8f/32.png) [@Vino\_Thiyagu](https://forum.ansible.com/u/Vino_Thiyagu)\
**Post date:** [March 7, 2019, 8:09am UTC](https://forum.ansible.com/t/lineinfile-path-local-and-remote-path/29823/3 "2019-03-07T08:09:05Z")

</div>

yes you are right . delegate\_to: 127.0.0.1 or delegate\_to: localhost
