Skip to content

Commit

Permalink
Add --purge option to ansible-pull
Browse files Browse the repository at this point in the history
Removes git checkout after playbook run.
  • Loading branch information
sfromm committed Oct 12, 2012
1 parent 034e8f5 commit 60d3e9f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bin/ansible-pull
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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__':
Expand Down

0 comments on commit 60d3e9f

Please sign in to comment.