# Split string by newline and use with with\_items

**URL:** <https://forum.ansible.com/t/split-string-by-newline-and-use-with-with-items/15063>\
**Category:** Ansible Project\
**Created:** [April 22, 2014, 1:22pm UTC](https://forum.ansible.com/t/split-string-by-newline-and-use-with-with-items/15063 "2014-04-22T13:22:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Romanovsky](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Max\_Romanovsky](https://forum.ansible.com/u/Max_Romanovsky)\
**Post date:** [April 22, 2014, 1:22pm UTC](https://forum.ansible.com/t/split-string-by-newline-and-use-with-with-items/15063/1 "2014-04-22T13:22:36Z")

</div>

Consider the following situation.  
It is necessary to execute arbitrary commands during deployment.  
Deployment is done using parameterized job in Jenkins CI. Multiline parameter contains commands separated by newline.  
Jenkins passes this parameter to Ansible using --extra-vars.  
Is it possible to split this parameter by line separator on Ansible side and pass this array to with\_items?

Thanks in advance.

---

<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:** [April 22, 2014, 2:24pm UTC](https://forum.ansible.com/t/split-string-by-newline-and-use-with-with-items/15063/2 "2014-04-22T14:24:52Z")

</div>

It should be as easy as:

with\_items: somevar.splitlines()

I tested this locally an it worked as expected:

---

<div class="post-metadata">

**Author:** ![Max\_Romanovsky](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Max\_Romanovsky](https://forum.ansible.com/u/Max_Romanovsky)\
**Post date:** [April 22, 2014, 3:04pm UTC](https://forum.ansible.com/t/split-string-by-newline-and-use-with-with-items/15063/3 "2014-04-22T15:04:57Z")

</div>

Thanks! It works great! 🙂

---

<div class="post-metadata">

**Author:** ![Naween\_Ghimire](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Naween\_Ghimire](https://forum.ansible.com/u/Naween_Ghimire)\
**Post date:** [September 20, 2014, 8:30pm UTC](https://forum.ansible.com/t/split-string-by-newline-and-use-with-with-items/15063/4 "2014-09-20T20:30:22Z")

</div>

Hi Max,

You say that you are using --extra-vars in jenkins to pass variables to ansible, I have been trying to do that, but the execute shell adds extra quotes around my --extra-vars and so the ansible-plabyook is unable to read the correct value of the variables defined. How did you get around this ?

If you could share the way you are using it in your case it would be a great help.

Regards,  
Naween
