From 60d3e9f3de7b4dd985f0659810c6a81310a60a06 Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Fri, 12 Oct 2012 07:53:56 -0700 Subject: [PATCH] Add --purge option to ansible-pull Removes git checkout after playbook run. --- bin/ansible-pull | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bin/ansible-pull b/bin/ansible-pull index 271542050c1..7863d3b695a 100755 --- a/bin/ansible-pull +++ b/bin/ansible-pull @@ -37,6 +37,7 @@ # the git repo must contain at least one of these playbooks. import os +import shutil import subprocess import sys import datetime @@ -92,6 +93,8 @@ def main(args): """ Set up and run a local playbook """ usage = "%prog [options] [playbook.yml]" parser = OptionParser(usage=usage) + parser.add_option('--purge', default=False, action='store_true', + help='Purge git checkout after playbook run') parser.add_option('-d', '--directory', dest='dest', default=None, help='Directory to clone git repository to') parser.add_option('-U', '--url', dest='url', default=None, @@ -127,6 +130,14 @@ def main(args): cmd = 'ansible-playbook -c local %s' % playbook os.chdir(options.dest) rc = _run(cmd) + + if options.purge: + os.chdir('/') + try: + shutil.rmtree(options.dest) + except Exception, e: + print >>sys.stderr, "Failed to remove %s: %s" % (options.dest, str(e)) + return rc if __name__ == '__main__':