with_sequence: / with_items: question

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 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!

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.

Thanks Matt!