Add --purge option to ansible-pull

Removes git checkout after playbook run.
This commit is contained in:
Stephen Fromm 2012-10-12 07:53:56 -07:00
parent 034e8f59ed
commit 60d3e9f3de

View file

@ -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__':