mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -07:00
Check module_path permissions when creating ssh_wrapper for git
If the module directory is not writable/executable to the current user (most likely because of a sudo to a non-root user), the ssh_wrapper will be created in the default location for mkstemp() calls. To facilitate the deletion of these new files, a new mechanism for cleaning up files created by the module was also added. Fixes #7375
This commit is contained in:
parent
3b8a35d65e
commit
df877f2e79
2 changed files with 22 additions and 2 deletions
|
@ -182,6 +182,7 @@ class AnsibleModule(object):
|
|||
self.supports_check_mode = supports_check_mode
|
||||
self.check_mode = False
|
||||
self.no_log = no_log
|
||||
self.cleanup_files = []
|
||||
|
||||
self.aliases = {}
|
||||
|
||||
|
@ -898,11 +899,20 @@ class AnsibleModule(object):
|
|||
def from_json(self, data):
|
||||
return json.loads(data)
|
||||
|
||||
def add_cleanup_file(self, path):
|
||||
if path not in self.cleanup_files:
|
||||
self.cleanup_files.append(path)
|
||||
|
||||
def do_cleanup_files(self):
|
||||
for path in self.cleanup_files:
|
||||
self.cleanup(path)
|
||||
|
||||
def exit_json(self, **kwargs):
|
||||
''' return from the module, without error '''
|
||||
self.add_path_info(kwargs)
|
||||
if not 'changed' in kwargs:
|
||||
kwargs['changed'] = False
|
||||
self.do_cleanup_files()
|
||||
print self.jsonify(kwargs)
|
||||
sys.exit(0)
|
||||
|
||||
|
@ -911,6 +921,7 @@ class AnsibleModule(object):
|
|||
self.add_path_info(kwargs)
|
||||
assert 'msg' in kwargs, "implementation error -- msg to explain the error is required"
|
||||
kwargs['failed'] = True
|
||||
self.do_cleanup_files()
|
||||
print self.jsonify(kwargs)
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -958,7 +969,7 @@ class AnsibleModule(object):
|
|||
self.fail_json(msg='Could not make backup of %s to %s: %s' % (fn, backupdest, e))
|
||||
return backupdest
|
||||
|
||||
def cleanup(self,tmpfile):
|
||||
def cleanup(self, tmpfile):
|
||||
if os.path.exists(tmpfile):
|
||||
try:
|
||||
os.unlink(tmpfile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue