ansible/ansible — pull request #3498 by SirScott (2013-07-10 22:25:20+00:00)
Title: Add a split filter.

Often it is convenient to pass an argument on the command line that could be used as an iterable. This patch provides a 'split' filter which mimics the python str.split interface.

An example playbook using it:

---
- hosts: localhost
tasks:
- debug: msg="{{ item }}"
with_items: "{{ foo|split(sep=',') }}"

Executing it:

$ ansible-playbook test.yml -e "foo=1,2,3"

PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [debug msg="{{item}}"] **************************************************
ok: [localhost] => (item=1) => {"item": "1", "msg": "1"}
ok: [localhost] => (item=2) => {"item": "2", "msg": "2"}
ok: [localhost] => (item=3) => {"item": "3", "msg": "3"}

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