Skip to content

feature request: looping over blocks #13262

@smiller171

Description

@smiller171
Issue Type:

Feature Idea

Component Name:

blocks

Ansible Version:

Ansible 2.0.0_rc-1

Ansible Configuration:

NA

Environment:

Ubuntu 15.10

Summary of Decision:

We're open to implementing this but want it to go through the proposal process. Please see: #13262 (comment) for details.

Summary:

There are a number of use-cases where it would be valuable to be able to loop over a block of tasks, such that a few tasks are done in order, and that specific block of tasks are looped over for some set of values. It seems that the new block functionality could lend itself well to this if you were to enable looping over blocks.

Steps To Reproduce:
- hosts: localhost
  connection: local
  tasks:
  - block:
    - debug: msg="task 1 loop {{item}}"
    - debug: msg="task 2 loop {{item}}"
    with_items:
    - "1"
    - "2"
Expected Results:
PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [debug msg=task 1 loop {{item}}] ******************************************
ok: [localhost] => {
    "changed": false, 
    "msg": "task 1 loop 1"
}

TASK [debug msg=task 2 loop {{item}}] ******************************************
ok: [localhost] => {
    "changed": false, 
    "msg": "task 2 loop 1"
}

TASK [debug msg=task 1 loop {{item}}] ******************************************
ok: [localhost] => {
    "changed": false, 
    "msg": "task 1 loop 2"
}

TASK [debug msg=task 2 loop {{item}}] ******************************************
ok: [localhost] => {
    "changed": false, 
    "msg": "task 2 loop 2"
}

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=0
Actual Results:
ERROR! 'with_items' is not a valid attribute for a Block

The error appears to have been in '/root/test.yml': line 5, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  tasks:
  - block:
    ^ here

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects_2.0This issue/PR affects Ansible v2.0c:playbook/blockc:playbook/loop_controlfeatureThis issue/PR relates to a feature request.support:coreThis issue/PR relates to code supported by the Ansible Engineering Team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions