ansible
ansible copied to clipboard
loop_control "early exit" feature
ISSUE TYPE
- Feature Pull Request
posisbly fixes #46203 by providing 'until for includes'
COMPONENT NAME
core
cc @acozine click here for bot help
Looks like a very nice way to handle these kind of loops!
Not sure that these changes would fix #46203 I tested @bcoca's branch locally with this playbook:
- hosts: localhost
gather_facts: false
tasks:
- name: testing block looping
block:
- debug:
msg: "{{ item }}"
loop:
- 1
- 2
- 3
loop_control:
until: item > 2
Which yields:
ansible-playbook test/integration/targets/loop_control/block_play.yml
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the
Ansible engine, or trying out features under development. This is a rapidly changing source of code and can become unstable at any
point.
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
ERROR! 'loop' is not a valid attribute for a Block
The error appears to be in '/Users/jeffmartin/dev/ansible/test/integration/targets/loop_control/block_play.yml': line 4, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
- name: testing block looping
^ here
Am I missing something?
Ah I see what I was missing, this fix would only apply to includes
not block
. This works great:
- hosts: localhost
gather_facts: false
tasks:
- name: testing inlcude looping
include_tasks: some_tasks.yml
loop:
- 1
- 2
- 3
loop_control:
until: item > 2
Can you guys please fix this, the people are really hoping for this feature.
I've had some success using when
as described here. This is not exactly an until
or break
feature, but it can be used for the same purpose.
@bcoca is this still intended to be made a core feature? would be very useful to have, it makes a lot of sense to be able to break out of a loop based on any condition.
probably, but not a priority right now
Is this still being worked on?
@LennertMertens it is still on my list, but it is not planned to make it in anytime soon