# Repeat a task based on a csv string from extra\_var

**URL:** <https://forum.ansible.com/t/repeat-a-task-based-on-a-csv-string-from-extra-var/27033>\
**Category:** Ansible Project\
**Created:** [March 19, 2018, 3:17am UTC](https://forum.ansible.com/t/repeat-a-task-based-on-a-csv-string-from-extra-var/27033 "2018-03-19T03:17:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoFigure](https://avatars.discourse-cdn.com/v4/letter/g/a587f6/32.png) [@GoFigure](https://forum.ansible.com/u/GoFigure)\
**Post date:** [March 19, 2018, 3:17am UTC](https://forum.ansible.com/t/repeat-a-task-based-on-a-csv-string-from-extra-var/27033/1 "2018-03-19T03:17:56Z")

</div>

Hello All,

There is a specific nut I am trying to crack in ansible. We want to dev a job template that add disks to and server instance. The size and number of disk will be provided as an extra\_var csv string, eg. 10,100,25,200 would add 4 disks of sizes 10GB, 100GB, 25GB & 200GB. We have the task ready and it works, so adding one disk is not a problem, but how do we then repeat that task for the next disk? Its not a question of nuts and bolts of adding disks, its a question how do we take the csv string (not file) and then loop the task.

Looks like this is possible in Ansible, as per the below articles.  
[http://docs.ansible.com/ansible/latest/playbooks\_loops.html](http://docs.ansible.com/ansible/latest/playbooks_loops.html)  
[https://groups.google.com/forum/#!searchin/ansible-project/.split$20with\_items$20comma|sort:date/ansible-project/jpqKAXezl40/TItF3W48AAAJ](https://groups.google.com/forum/#!searchin/ansible-project/.split$20with_items$20comma%7Csort:date/ansible-project/jpqKAXezl40/TItF3W48AAAJ)  
[https://groups.google.com/forum/#!searchin/ansible-project/.split|sort:date/ansible-project/QmvdMpaLxwY/Czv0irDoCgAJ](https://groups.google.com/forum/#!searchin/ansible-project/.split%7Csort:date/ansible-project/QmvdMpaLxwY/Czv0irDoCgAJ)  
[https://groups.google.com/forum/#!searchin/ansible-project/.split|sort:date/ansible-project/x2MCN2Qc4GU/fQSvxJEiAQAJ](https://groups.google.com/forum/#!searchin/ansible-project/.split%7Csort:date/ansible-project/x2MCN2Qc4GU/fQSvxJEiAQAJ)

or is this something that requires developing a module?

Thanks

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [March 19, 2018, 5:05am UTC](https://forum.ansible.com/t/repeat-a-task-based-on-a-csv-string-from-extra-var/27033/2 "2018-03-19T05:05:44Z")

</div>

`

- hosts: localhost  
vars:  
foo: 10,30,20  
tasks:
- debug:  
var: item  
with\_list: “{{ foo.split(‘,’) }}”

`

`

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> (item=10) =\> {  
“attempts”: 1,  
“changed”: false,  
“item”: “10”  
}  
ok: [localhost] =\> (item=30) =\> {  
“attempts”: 1,  
“changed”: false,  
“item”: “30”  
}  
ok: [localhost] =\> (item=20) =\> {  
“attempts”: 1,  
“changed”: false,  
“item”: “20”  
}

`

---

<div class="post-metadata">

**Author:** ![GoFigure](https://avatars.discourse-cdn.com/v4/letter/g/a587f6/32.png) [@GoFigure](https://forum.ansible.com/u/GoFigure)\
**Post date:** [March 19, 2018, 6:03am UTC](https://forum.ansible.com/t/repeat-a-task-based-on-a-csv-string-from-extra-var/27033/3 "2018-03-19T06:03:36Z")

</div>

Thanks Flowerysong, that helps… been playing a bit, but this does exactly the trick.
