Skip to content

Commit 60b82f7

Browse files
authored
Do not use the fstab parameter on openbsd for mounting (ansible#5805)
* Do not use the fstab parameter on openbsd for mounting OpenBSD's mount command doesn't allow selecting which fstab file to use. So if we're operating on the live filesystem (mount or remount) return an error if the user specified an fstab file. Fixes ansible#5591 * Fix the logic inversion (thanks to @landryb)
1 parent 4f6189b commit 60b82f7

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

system/mount.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@
9090
choices: ["present", "absent", "mounted", "unmounted"]
9191
fstab:
9292
description:
93-
- File to use instead of C(/etc/fstab). You shouldn't use that option
93+
- File to use instead of C(/etc/fstab). You shouldn't use this option
9494
unless you really know what you are doing. This might be useful if
95-
you need to configure mountpoints in a chroot environment.
95+
you need to configure mountpoints in a chroot environment. OpenBSD
96+
does not allow specifying alternate fstab files with mount so do not
97+
use this on OpenBSD with any state that operates on the live filesystem.
9698
required: false
9799
default: /etc/fstab (/etc/vfstab on Solaris)
98100
boot:
@@ -308,14 +310,14 @@ def unset_mount(module, args):
308310

309311
return (args['name'], changed)
310312

311-
def _set_fstab_args(args):
313+
def _set_fstab_args(fstab_file):
312314
result = []
313-
if 'fstab' in args and args['fstab'] != '/etc/fstab':
315+
if fstab_file and fstab_file != '/etc/fstab':
314316
if get_platform().lower().endswith('bsd'):
315317
result.append('-F')
316318
else:
317319
result.append('-T')
318-
result.append(args['fstab'])
320+
result.append(fstab_file)
319321
return result
320322

321323
def mount(module, args):
@@ -328,7 +330,13 @@ def mount(module, args):
328330
if ismount(name):
329331
return remount(module, mount_bin, args)
330332

331-
cmd += _set_fstab_args(args)
333+
if get_platform().lower() == 'openbsd':
334+
# Use module.params['fstab'] here as args['fstab'] has been set to the
335+
# default value.
336+
if module.params['fstab'] is not None:
337+
module.fail_json(msg='OpenBSD does not support alternate fstab files. Do not specify the fstab parameter for OpenBSD hosts')
338+
else:
339+
cmd += _set_fstab_args(args['fstab'])
332340

333341
cmd += [name]
334342

@@ -364,7 +372,13 @@ def remount(module, mount_bin, args):
364372
else:
365373
cmd += ['-o', 'remount' ]
366374

367-
cmd += _set_fstab_args(args)
375+
if get_platform().lower() == 'openbsd':
376+
# Use module.params['fstab'] here as args['fstab'] has been set to the
377+
# default value.
378+
if module.params['fstab'] is not None:
379+
module.fail_json(msg='OpenBSD does not support alternate fstab files. Do not specify the fstab parameter for OpenBSD hosts')
380+
else:
381+
cmd += _set_fstab_args(args['fstab'])
368382
cmd += [ args['name'], ]
369383
out = err = ''
370384
try:
@@ -564,7 +578,7 @@ def main():
564578
argument_spec=dict(
565579
boot=dict(default='yes', choices=['yes', 'no']),
566580
dump=dict(),
567-
fstab=dict(default='/etc/fstab'),
581+
fstab=dict(default=None),
568582
fstype=dict(),
569583
name=dict(required=True, type='path'),
570584
opts=dict(),
@@ -586,26 +600,32 @@ def main():
586600
# name, src, fstype, opts, boot, passno, state, fstab=/etc/vfstab
587601
# linux args:
588602
# name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
589-
if get_platform() == 'SunOS':
603+
# Note: Do not modify module.params['fstab'] as we need to know if the user
604+
# explicitly specified it in mount() and remount()
605+
if get_platform().lower() == 'sunos':
590606
args = dict(
591607
name=module.params['name'],
592608
opts='-',
593609
passno='-',
594-
fstab='/etc/vfstab',
610+
fstab=module.params['fstab'],
595611
boot='yes'
596612
)
613+
if args['fstab'] is None:
614+
args['fstab'] = '/etc/vfstab'
597615
else:
598616
args = dict(
599617
name=module.params['name'],
600618
opts='defaults',
601619
dump='0',
602620
passno='0',
603-
fstab='/etc/fstab'
621+
fstab=module.params['fstab']
604622
)
623+
if args['fstab'] is None:
624+
args['fstab'] = '/etc/fstab'
605625

606-
# FreeBSD doesn't have any 'default' so set 'rw' instead
607-
if get_platform() == 'FreeBSD':
608-
args['opts'] = 'rw'
626+
# FreeBSD doesn't have any 'default' so set 'rw' instead
627+
if get_platform() == 'FreeBSD':
628+
args['opts'] = 'rw'
609629

610630
linux_mounts = []
611631

@@ -624,9 +644,6 @@ def main():
624644
if module.params[key] is not None:
625645
args[key] = module.params[key]
626646

627-
if get_platform() == 'SunOS' and args['fstab'] == '/etc/fstab':
628-
args['fstab'] = '/etc/vfstab'
629-
630647
# If fstab file does not exist, we first need to create it. This mainly
631648
# happens when fstab option is passed to the module.
632649
if not os.path.exists(args['fstab']):

0 commit comments

Comments
 (0)