From 690738ea32a317ff6de4927d7168ba5053c49a87 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Tue, 9 Apr 2013 01:53:40 -0400 Subject: [PATCH] implement --start-at-task option to hop to a specific task before starting running them --- bin/ansible-playbook | 4 ++++ lib/ansible/callbacks.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 917d00e6ff7..751bbee1fc9 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -74,6 +74,8 @@ def main(args): help="do list all tasks that would be executed") parser.add_option('--step', dest='step', action='store_true', help="one-step-at-a-time: confirm each task before running") + parser.add_option('--start-at-task', dest='start_at', + help="start the playbook with a task matching this name") options, args = parser.parse_args(args) @@ -115,6 +117,8 @@ def main(args): playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY) if options.step: playbook_cb.step = options.step + if options.start_at: + playbook_cb.start_at = options.start_at runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY) pb = ansible.playbook.PlayBook( diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py index d241806740d..cf204bbdb26 100644 --- a/lib/ansible/callbacks.py +++ b/lib/ansible/callbacks.py @@ -21,6 +21,7 @@ import getpass import os import subprocess import random +import fnmatch from ansible.color import stringc cowsay = None @@ -460,8 +461,15 @@ class PlaybookCallbacks(object): msg = "TASK: [%s]" % name if is_conditional: msg = "NOTIFIED: [%s]" % name - - if hasattr(self, 'step') and self.step: + + if hasattr(self, 'start_at'): + if name == self.start_at or fnmatch.fnmatch(name, self.start_at): + # we found out match, we can get rid of this now + del self.start_at + + if hasattr(self, 'start_at'): # we still have start_at so skip the task + self.skip_task = True + elif hasattr(self, 'step') and self.step: resp = raw_input('Perform task: %s (y/n/c): ' % name) if resp.lower() in ['y','yes']: self.skip_task = False