mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 04:41:26 -07:00
mount: Add option to backup fstab file (#33734)
This fix adds option to create a backup of fstab file before making any changes to it. Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
51475cd623
commit
dbc6963617
1 changed files with 15 additions and 3 deletions
|
@ -84,6 +84,14 @@ options:
|
||||||
type: bool
|
type: bool
|
||||||
default: 'yes'
|
default: 'yes'
|
||||||
version_added: '2.2'
|
version_added: '2.2'
|
||||||
|
backup:
|
||||||
|
description:
|
||||||
|
- Create a backup file including the timestamp information so you can get
|
||||||
|
the original file back if you somehow clobbered it incorrectly.
|
||||||
|
required: false
|
||||||
|
choices: [ "yes", "no" ]
|
||||||
|
default: "no"
|
||||||
|
version_added: '2.5'
|
||||||
notes:
|
notes:
|
||||||
- As of Ansible 2.3, the I(name) option has been changed to I(path) as
|
- As of Ansible 2.3, the I(name) option has been changed to I(path) as
|
||||||
default, but I(name) still works as well.
|
default, but I(name) still works as well.
|
||||||
|
@ -125,7 +133,10 @@ from ansible.module_utils.six import iteritems
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
def write_fstab(lines, path):
|
def write_fstab(module, lines, path):
|
||||||
|
if module.params['backup']:
|
||||||
|
module.backup_local(path)
|
||||||
|
|
||||||
fs_w = open(path, 'w')
|
fs_w = open(path, 'w')
|
||||||
|
|
||||||
for l in lines:
|
for l in lines:
|
||||||
|
@ -236,7 +247,7 @@ def set_mount(module, args):
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if changed and not module.check_mode:
|
if changed and not module.check_mode:
|
||||||
write_fstab(to_write, args['fstab'])
|
write_fstab(module, to_write, args['fstab'])
|
||||||
|
|
||||||
return (args['name'], changed)
|
return (args['name'], changed)
|
||||||
|
|
||||||
|
@ -298,7 +309,7 @@ def unset_mount(module, args):
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if changed and not module.check_mode:
|
if changed and not module.check_mode:
|
||||||
write_fstab(to_write, args['fstab'])
|
write_fstab(module, to_write, args['fstab'])
|
||||||
|
|
||||||
return (args['name'], changed)
|
return (args['name'], changed)
|
||||||
|
|
||||||
|
@ -548,6 +559,7 @@ def main():
|
||||||
opts=dict(type='str'),
|
opts=dict(type='str'),
|
||||||
passno=dict(type='str'),
|
passno=dict(type='str'),
|
||||||
src=dict(type='path'),
|
src=dict(type='path'),
|
||||||
|
backup=dict(default=False, type='bool'),
|
||||||
state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted']),
|
state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted']),
|
||||||
),
|
),
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue