with_sequence: / with_items: question

615 views
Skip to first unread message

Jimmy Prescott

unread,
May 27, 2014, 12:16:02 PM5/27/14
to ansible...@googlegroups.com
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!

Matt Martz

unread,
May 27, 2014, 12:44:28 PM5/27/14
to ansible...@googlegroups.com
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.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/07a3acaf-3495-431d-b357-1657cda651ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
ma...@sivel.net
http://sivel.net/

Jimmy Prescott

unread,
May 27, 2014, 1:08:17 PM5/27/14
to ansible...@googlegroups.com
Thanks Matt!
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages