# with\_sequence: / with\_items: question

**URL:** <https://forum.ansible.com/t/with-sequence-with-items-question/15340>\
**Category:** Ansible Project\
**Created:** [May 27, 2014, 4:16pm UTC](https://forum.ansible.com/t/with-sequence-with-items-question/15340 "2014-05-27T16:16:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmy\_Prescott](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jimmy\_Prescott](https://forum.ansible.com/u/Jimmy_Prescott)\
**Post date:** [May 27, 2014, 4:16pm UTC](https://forum.ansible.com/t/with-sequence-with-items-question/15340/1 "2014-05-27T16:16:02Z")

</div>

I am probably have my syntax wrong but I am trying to reduce the amount of code in my playbook when creating cloud block storage volumes using rax\_cbs. Here is what it looks like currently and works great:

- name: Build a Block Storage Volume  
gather\_facts: False  
hosts: localhost  
connection: local  
tasks:
- name: Create glustor1  
local\_action:  
module: rax\_cbs  
name: glustor1  
description: brick2  
volume\_type: SATA  
size: 100  
region: DFW  
wait: yes  
state: present  
meta:  
app: glustor1  
register: raxvolumes
- name: Create glustor2  
local\_action:  
module: rax\_cbs  
name: glustor2  
description: brick2  
volume\_type: SATA  
size: 100  
region: DFW  
wait: yes  
state: present  
meta:  
app: glustor2  
register: raxvolumes
- name: Create glustor3  
local\_action:  
module: rax\_cbs  
name: glustor3  
description: brick3  
volume\_type: SATA  
size: 100  
region: DFW  
wait: yes  
state: present  
meta:  
app: glustor3  
register: raxvolumes
- name: Create glustor4  
local\_action:  
module: rax\_cbs  
name: glustor4  
description: brick4  
volume\_type: SATA  
size: 100  
region: DFW  
wait: yes  
state: present  
meta:  
app: glustor4  
register: raxvolumes

And I have tried the following based on [http://docs.ansible.com/playbooks\_loops.html](http://docs.ansible.com/playbooks_loops.html) but it errors due to item not being defined:

- name: Build a Block Storage Volume # I also tried changing {{ item }} to {{ format }}  
gather\_facts: False  
hosts: localhost  
connection: local  
tasks:
- name: Create glustor bricks  
local\_action:  
module: rax\_cbs  
name: “{{ item }}”  
description: Glustor Brick  
volume\_type: SATA  
size: 100  
region: DFW  
wait: yes  
state: present  
with\_sequence: start=1 end=4 format=glustor%d  
register: raxvolumes

TASK: [Create glustor bricks] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost] =\> One or more undefined variables: ‘item’ is undefined

FATAL: all hosts have already failed – aborting

Also tried the following:

- name: Build a Block Storage Volume  
gather\_facts: False  
hosts: localhost  
connection: local  
tasks:
- name: Create glustor bricks  
local\_action:  
module: rax\_cbs  
name: “{{ item }}”  
description: Glustor Brick  
volume\_type: SATA  
size: 100  
region: DFW  
wait: yes  
state: present  
with\_items:
- glustor1
- glustor2
- glustor3
- glustor4  
register: raxvolumes

TASK: [Create glustor bricks] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost] =\> One or more undefined variables: ‘item’ is undefined

FATAL: all hosts have already failed – aborting

Thanks for pointing me in the right direction!

---

<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:** [May 27, 2014, 4:44pm UTC](https://forum.ansible.com/t/with-sequence-with-items-question/15340/2 "2014-05-27T16:44:25Z")

</div>

Your with\_items or with\_sequence is indented too far. It should match the indentation of “register” and “name”.

Also be aware of how register and with\_ works. There are some docs on the playbooks loops page in the docs.

---

<div class="post-metadata">

**Author:** ![Jimmy\_Prescott](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jimmy\_Prescott](https://forum.ansible.com/u/Jimmy_Prescott)\
**Post date:** [May 27, 2014, 5:08pm UTC](https://forum.ansible.com/t/with-sequence-with-items-question/15340/3 "2014-05-27T17:08:17Z")

</div>

Thanks Matt!
