Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mount: Check if src exists before mounted #61752

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/ansible/modules/system/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down