mount return backup_file

Fixes https://github.com/ansible-collections/ansible.posix/issues/126

Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
Adam Miller
2021-01-05 17:23:15 -06:00
committed by Abhijeet Kasurde
parent 1793cd70c4
commit 41e5b8428f
3 changed files with 123 additions and 131 deletions

View File

@@ -171,7 +171,6 @@ EXAMPLES = r'''
fstype: nfs
'''
import errno
import os
import platform
@@ -184,8 +183,11 @@ from ansible.module_utils.parsing.convert_bool import boolean
def write_fstab(module, lines, path):
if module.params['backup']:
module.backup_local(path)
backup_file = module.backup_local(path)
else:
backup_file = ""
fs_w = open(path, 'w')
@@ -195,6 +197,8 @@ def write_fstab(module, lines, path):
fs_w.flush()
fs_w.close()
return backup_file
def _escape_fstab(v):
"""Escape invalid characters in fstab fields.
@@ -317,7 +321,7 @@ def _set_mount_save_old(module, args):
changed = True
if changed and not module.check_mode:
write_fstab(module, to_write, args['fstab'])
args['backup_file'] = write_fstab(module, to_write, args['fstab'])
return (args['name'], old_lines, changed)
@@ -692,6 +696,7 @@ def main():
if platform.system() == 'FreeBSD':
args['opts'] = 'rw'
args['backup_file'] = ""
linux_mounts = []
# Cache all mounts here in order we have consistent results if we need to