mount: Check if src exists before mounted (#61752)

Fixes: #59183

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2019-09-10 21:42:10 +05:30 committed by GitHub
parent a3e9d14702
commit 72023d7462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -662,8 +662,12 @@ def main():
if not os.path.exists(args['fstab']):
if not os.path.exists(os.path.dirname(args['fstab'])):
os.makedirs(os.path.dirname(args['fstab']))
try:
open(args['fstab'], 'a').close()
except PermissionError as e:
module.fail_json(msg="Failed to open %s due to permission issue" % args['fstab'])
except Exception as e:
module.fail_json(msg="Failed to open %s due to %s" % (args['fstab'], to_native(e)))
# absent:
# Remove from fstab and unmounted.
@ -706,6 +710,9 @@ def main():
changed = True
elif state == 'mounted':
if not os.path.exists(args['src']):
module.fail_json(msg="Unable to mount %s as it does not exist" % args['src'])
if not os.path.exists(name) and not module.check_mode:
try:
os.makedirs(name)