1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[mount] make sure fstab exists

This is mainly to prevent from failing with no such file or directory
during module execution.
This commit is contained in:
Sébastien Gross 2014-07-21 18:32:02 +02:00
parent f2e2337d07
commit 48128ec0ab

View file

@ -267,6 +267,13 @@ def main():
if module.params['fstab'] is not None: if module.params['fstab'] is not None:
args['fstab'] = module.params['fstab'] args['fstab'] = module.params['fstab']
# if fstab file does not exist, we first need to create it. This mainly
# happens when fstab optin is passed to the module.
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()
# absent == remove from fstab and unmounted # absent == remove from fstab and unmounted
# unmounted == do not change fstab state, but unmount # unmounted == do not change fstab state, but unmount
# present == add to fstab, do not change mount state # present == add to fstab, do not change mount state