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

Fixes: #59183

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/62085/head
Abhijeet Kasurde 5 years ago committed by GitHub
parent a3e9d14702
commit 72023d7462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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']))
open(args['fstab'], 'a').close()
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)

Loading…
Cancel
Save