# Adding Multiple lines to file

**URL:** <https://forum.ansible.com/t/adding-multiple-lines-to-file/20520>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [February 10, 2016, 5:11pm UTC](https://forum.ansible.com/t/adding-multiple-lines-to-file/20520 "2016-02-10T17:11:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 10, 2016, 5:11pm UTC](https://forum.ansible.com/t/adding-multiple-lines-to-file/20520/1 "2016-02-10T17:11:21Z")

</div>

Hi

I want to add multiple lines to a host file on some Windows machines.

I tried using win\_lineinfile in the following playbook below…but it only added the last line.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [February 10, 2016, 5:15pm UTC](https://forum.ansible.com/t/adding-multiple-lines-to-file/20520/2 "2016-02-10T17:15:11Z")

</div>

You would probably want to loop over a list of “lines” using with\_items, and them just use “{{ item }}” for the “line” argument.

---

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 11, 2016, 10:19am UTC](https://forum.ansible.com/t/adding-multiple-lines-to-file/20520/3 "2016-02-11T10:19:56Z")

</div>

Hi Matt

How exactly would that look like in a playbook?

Cheers  
Mark

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 11, 2016, 11:31am UTC](https://forum.ansible.com/t/adding-multiple-lines-to-file/20520/4 "2016-02-11T11:31:47Z")

</div>

Lots of examples of the various ways to loop here: [http://docs.ansible.com/ansible/playbooks\_loops.html#standard-loops](http://docs.ansible.com/ansible/playbooks_loops.html#standard-loops)

Depending on what you are trying to achieve, you might actually find the win\_template module is easier to work with rather than multiple calls to win\_lineinfile

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Mark\_Matthews](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@Mark\_Matthews](https://forum.ansible.com/u/Mark_Matthews)\
**Post date:** [February 11, 2016, 5:04pm UTC](https://forum.ansible.com/t/adding-multiple-lines-to-file/20520/5 "2016-02-11T17:04:22Z")

</div>

Hi Jon

Thanks for the response.  
I was actually able to find a work around. Not a great solution, so will look at win\_template.
