Repeat a task based on a csv string from extra_var

24 views
Skip to first unread message

GoFigure

unread,
Mar 18, 2018, 11:17:56 PM3/18/18
to Ansible Project
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.


or is this something that requires developing a module?

Thanks

flowerysong

unread,
Mar 19, 2018, 1:05:44 AM3/19/18
to Ansible Project
On Sunday, March 18, 2018 at 11:17:56 PM UTC-4, GoFigure wrote:
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.

- 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"
}

GoFigure

unread,
Mar 19, 2018, 2:03:36 AM3/19/18
to Ansible Project
Thanks Flowerysong, that helps.... been playing a bit, but this does exactly the trick.
Reply all
Reply to author
Forward
0 new messages