Split string by newline and use with with_items

8,781 views
Skip to first unread message

Max Romanovsky

unread,
Apr 22, 2014, 9:22:36 AM4/22/14
to ansible...@googlegroups.com
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.

Matt Martz

unread,
Apr 22, 2014, 10:24:52 AM4/22/14
to Max Romanovsky, ansible...@googlegroups.com
It should be as easy as:

with_items: somevar.splitlines()

I tested this locally an it worked as expected:
-- 
Matt Martz
ma...@sivel.net
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/41705b7c-1615-4414-963c-2848c6552950%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Max Romanovsky

unread,
Apr 22, 2014, 11:04:57 AM4/22/14
to ansible...@googlegroups.com, Max Romanovsky
Thanks! It works great! :)

Naween Ghimire

unread,
Sep 20, 2014, 4:30:22 PM9/20/14
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages