mount: Check if src exists before mounted (#61752)
Fixes: #59183 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
a3e9d14702
commit
72023d7462
1 changed files with 9 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue