From af44bd4ddded532af522d84cbc4cb878aca56f13 Mon Sep 17 00:00:00 2001 From: David Shrewsbury Date: Tue, 21 Apr 2020 03:39:17 -0400 Subject: [PATCH] Fix --start-at-task when skipping tasks with no name (#68951) Using --start-at-task on a playbook with tasks with no name would fail if those unnamed tasks were encountered before the targetted start task. --- changelogs/fragments/68569-start-at-fix.yaml | 2 ++ lib/ansible/executor/play_iterator.py | 2 +- test/integration/targets/play_iterator/aliases | 1 + test/integration/targets/play_iterator/playbook.yml | 10 ++++++++++ test/integration/targets/play_iterator/runme.sh | 5 +++++ 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/68569-start-at-fix.yaml create mode 100644 test/integration/targets/play_iterator/aliases create mode 100644 test/integration/targets/play_iterator/playbook.yml create mode 100755 test/integration/targets/play_iterator/runme.sh diff --git a/changelogs/fragments/68569-start-at-fix.yaml b/changelogs/fragments/68569-start-at-fix.yaml new file mode 100644 index 00000000000..df1675ebb91 --- /dev/null +++ b/changelogs/fragments/68569-start-at-fix.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Using --start-at-task would fail when it attempted to skip over tasks with no name. diff --git a/lib/ansible/executor/play_iterator.py b/lib/ansible/executor/play_iterator.py index 0fdcb2fedcc..c06b232d2b6 100644 --- a/lib/ansible/executor/play_iterator.py +++ b/lib/ansible/executor/play_iterator.py @@ -201,7 +201,7 @@ class PlayIterator: (s, task) = self.get_next_task_for_host(host, peek=True) if s.run_state == self.ITERATING_COMPLETE: break - if task.name == play_context.start_at_task or fnmatch.fnmatch(task.name, play_context.start_at_task) or \ + if task.name == play_context.start_at_task or (task.name and fnmatch.fnmatch(task.name, play_context.start_at_task)) or \ task.get_name() == play_context.start_at_task or fnmatch.fnmatch(task.get_name(), play_context.start_at_task): start_at_matched = True break diff --git a/test/integration/targets/play_iterator/aliases b/test/integration/targets/play_iterator/aliases new file mode 100644 index 00000000000..3005e4b26d0 --- /dev/null +++ b/test/integration/targets/play_iterator/aliases @@ -0,0 +1 @@ +shippable/posix/group4 diff --git a/test/integration/targets/play_iterator/playbook.yml b/test/integration/targets/play_iterator/playbook.yml new file mode 100644 index 00000000000..76100c6089c --- /dev/null +++ b/test/integration/targets/play_iterator/playbook.yml @@ -0,0 +1,10 @@ +--- +- hosts: localhost + gather_facts: false + tasks: + - name: + debug: + msg: foo + - name: "task 2" + debug: + msg: bar diff --git a/test/integration/targets/play_iterator/runme.sh b/test/integration/targets/play_iterator/runme.sh new file mode 100755 index 00000000000..9f30d9e7a2f --- /dev/null +++ b/test/integration/targets/play_iterator/runme.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook playbook.yml --start-at-task 'task 2' "$@"