Sha256: 353863849fe45947b30e7e05378ecf03e8e4336ae464df1cd43243a0bf2c4b58
Contents?: true
Size: 1.52 KB
Versions: 10
Compression:
Stored size: 1.52 KB
Contents
#!/usr/bin/python # import some python modules that we'll use. These are all # available in Python's core import datetime import sys import json import os import shlex import errno import subprocess import contextlib def mkdir_p(path): try: os.makedirs(path) except OSError as exc: # Python >2.5 if exc.errno == errno.EEXIST and os.path.isdir(path): pass else: raise def contians_files(path): for dirpath, dirnames, filenames in os.walk(path): if len(filenames) > 0: return True @contextlib.contextmanager def cd(newdir): prevdir = os.getcwd() os.chdir(os.path.expanduser(newdir)) try: yield finally: os.chdir(prevdir) def main(): module = AnsibleModule( argument_spec = dict( path=dict(required=True), ), supports_check_mode = False, ) changed = False path = module.params['path'] if os.path.isdir(path) is False: mkdir_p(path) changed = True keep_path = os.path.join(path, '.gitkeep') if (not os.path.exists(keep_path)) and (not contians_files(path)): open(os.path.join(path, '.gitkeep'), 'a').close() with cd(path): subprocess.check_call(['git', 'add', '-f', '.gitkeep']) changed = True module.exit_json( changed = changed, ) # import module snippets from ansible.module_utils.basic import * from ansible.module_utils.known_hosts import * if __name__ == '__main__': main()
Version data entries
10 entries across 10 versions & 1 rubygems