Add --purge option to ansible-pull

Removes git checkout after playbook run.
pull/1307/head
Stephen Fromm 12 years ago
parent 034e8f59ed
commit 60d3e9f3de

@ -37,6 +37,7 @@
# the git repo must contain at least one of these playbooks. # the git repo must contain at least one of these playbooks.
import os import os
import shutil
import subprocess import subprocess
import sys import sys
import datetime import datetime
@ -92,6 +93,8 @@ def main(args):
""" Set up and run a local playbook """ """ Set up and run a local playbook """
usage = "%prog [options] [playbook.yml]" usage = "%prog [options] [playbook.yml]"
parser = OptionParser(usage=usage) 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, parser.add_option('-d', '--directory', dest='dest', default=None,
help='Directory to clone git repository to') help='Directory to clone git repository to')
parser.add_option('-U', '--url', dest='url', default=None, parser.add_option('-U', '--url', dest='url', default=None,
@ -127,6 +130,14 @@ def main(args):
cmd = 'ansible-playbook -c local %s' % playbook cmd = 'ansible-playbook -c local %s' % playbook
os.chdir(options.dest) os.chdir(options.dest)
rc = _run(cmd) 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 return rc
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save