# replace line in multiple files using lineinfile could anyone please help me.

**URL:** <https://forum.ansible.com/t/replace-line-in-multiple-files-using-lineinfile-could-anyone-please-help-me/31514>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [October 22, 2019, 7:48pm UTC](https://forum.ansible.com/t/replace-line-in-multiple-files-using-lineinfile-could-anyone-please-help-me/31514 "2019-10-22T19:48:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SARDARNI\_NK](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@SARDARNI\_NK](https://forum.ansible.com/u/SARDARNI_NK)\
**Post date:** [October 22, 2019, 7:48pm UTC](https://forum.ansible.com/t/replace-line-in-multiple-files-using-lineinfile-could-anyone-please-help-me/31514/1 "2019-10-22T19:48:32Z")

</div>



---

<div class="post-metadata">

**Author:** ![J111](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@J111](https://forum.ansible.com/u/J111)\
**Post date:** [October 23, 2019, 2:01am UTC](https://forum.ansible.com/t/replace-line-in-multiple-files-using-lineinfile-could-anyone-please-help-me/31514/2 "2019-10-23T02:01:45Z")

</div>

I found this if it works for you.

```auto
---
- name: test loop files
  hosts: server
  gather_facts: no
  vars:
    SVNRepName_Location: /mydata/myserver/ConServer1
    Password: Ansible
  tasks:
    - name: list file and register location
      raw: find /mydata/myserver/ConServer1 -type f -name "files*"
      register: files_found
    - name: debug file
      debug:
        var: files_found.stdout_lines

    - name: use the loop in task replace line in multiple file
      lineinfile:
        dest: "{{item}}"
        regexp: SomeLine
        line: " Password : {{ Password }}"
        state: present
      with_items:
        - "{{files_found.stdout_lines}}"

```

---

<div class="post-metadata">

**Author:** ![SARDARNI\_NK](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@SARDARNI\_NK](https://forum.ansible.com/u/SARDARNI_NK)\
**Post date:** [October 23, 2019, 3:30pm UTC](https://forum.ansible.com/t/replace-line-in-multiple-files-using-lineinfile-could-anyone-please-help-me/31514/3 "2019-10-23T15:30:28Z")

</div>

Thank you, J

In (/mydata/myserver/ConServer1 ) i have many files which are different extensions (yml,txt,j2,) how do use (/mydata/myserver/ConServer1 -type f -name “files\*”) “files\*” do i need to provide same “files\*” i don’t understand this ? do i need to provide any file extensions or filenames ?  
I was testing step by step for task

```auto
  - name: list file and register location
      raw: find /mydata/myserver/ConServer1 -type f -name "files*"
      register: files_found
    - name: debug file
      debug:
        var: files_found.stdout_lines

```

I got the output

```auto
PLAY [localhost] ***************************************************************

TASK [list file and register location] *****************************************
changed: [localhost] => {"changed": true, "rc": 0, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

TASK [debug file] **************************************************************
ok: [localhost] => {
    "files_found.stdout_lines": []
}

PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0   

```

```auto

```

Could you please let me know?

Thanks,  
Nav

---

<div class="post-metadata">

**Author:** ![SARDARNI\_NK](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@SARDARNI\_NK](https://forum.ansible.com/u/SARDARNI_NK)\
**Post date:** [October 23, 2019, 6:27pm UTC](https://forum.ansible.com/t/replace-line-in-multiple-files-using-lineinfile-could-anyone-please-help-me/31514/4 "2019-10-23T18:27:07Z")

</div>

Thank you, J

It worked for me.

I have updated the raw: find /mydata/myserver/ConServer1 -type f -name “\*.yml” .

Listing all the files and replacing them in multiple files.

Thanks,  
Nav
