lineinfile path local and remote path

17 views
Skip to first unread message

Ryan

unread,
Mar 4, 2019, 9:44:44 PM3/4/19
to Ansible Project
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?

Ryan

unread,
Mar 5, 2019, 2:07:42 PM3/5/19
to Ansible Project
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 }}"

Vino Thiyagu

unread,
Mar 7, 2019, 3:09:05 AM3/7/19
to Ansible Project
yes you are right .  delegate_to: 127.0.0.1 or   delegate_to: localhost
Reply all
Reply to author
Forward
0 new messages