Added state "remount" which will remount the device (#52649)

This commit is contained in:
Raul Mahiques 2019-07-19 08:59:27 +02:00 committed by Martin Krizek
parent a752e2a467
commit fd2116e26a
3 changed files with 79 additions and 2 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- Added a parameter to allow remounting a filesystem

View File

@ -74,9 +74,12 @@ options:
- C(absent) specifies that the device mount's entry will be removed from
I(fstab) and will also unmount the device and remove the mount
point.
- C(remounted) specifies that the device will be remounted for when you
want to force a refresh on the mount itself (added in 2.9). This will
always return changed=true.
type: str
required: true
choices: [ absent, mounted, present, unmounted ]
choices: [ absent, mounted, present, unmounted, remounted ]
fstab:
description:
- File to use instead of C(/etc/fstab).
@ -597,7 +600,7 @@ def main():
passno=dict(type='str'),
src=dict(type='path'),
backup=dict(type='bool', default=False),
state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted']),
state=dict(type='str', required=True, choices=['absent', 'mounted', 'present', 'unmounted', 'remounted']),
),
supports_check_mode=True,
required_if=(
@ -730,6 +733,14 @@ def main():
module.fail_json(msg="Error mounting %s: %s" % (name, msg))
elif state == 'present':
name, changed = set_mount(module, args)
elif state == 'remounted':
if not module.check_mode:
res, msg = remount(module, args)
if res:
module.fail_json(msg="Error remounting %s: %s" % (name, msg))
changed = True
else:
module.fail_json(msg='Unexpected position reached')

View File

@ -276,3 +276,67 @@
- "' 0 0' in optional_fields_content.stdout"
- "1 == optional_fields_content.stdout_lines | length"
when: ansible_system in ('Linux')
- name: Block to test remounted option
block:
- name: Create empty file
command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20
when: ansible_system in ('Linux')
- name: Format FS
filesystem:
fstype: ext3
dev: /tmp/myfs.img
when: ansible_system in ('Linux')
- name: Mount the FS for the first time
mount:
path: /tmp/myfs
src: /tmp/myfs.img
fstype: ext2
state: mounted
when: ansible_system in ('Linux')
- name: Get the last write time
shell: "dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last\ write\ time: |cut -d: -f2-"
register: last_write_time
when: ansible_system in ('Linux')
- name: Wait 2 second
pause:
seconds: 2
when: ansible_system in ('Linux')
- name: Test if the FS is remounted
mount:
path: /tmp/myfs
state: remounted
when: ansible_system in ('Linux')
- name: Get again the last write time
shell: "dumpe2fs /tmp/myfs.img 2>/dev/null | grep -i last\ write\ time: |cut -d: -f2-"
register: last_write_time2
when: ansible_system in ('Linux')
- name: Fail if they are the same
fail:
msg: "Filesytem was not remounted, testing of the module failed!"
when: last_write is defined and last_write_time2 is defined and last_write_time.stdout == last_write_time2.stdout and ansible_system in ('Linux')
always:
- name: Umount the test FS
mount:
path: /tmp/myfs
src: /tmp/myfs.img
opts: loop
state: absent
when: ansible_system in ('Linux')
- name: Remove the test FS
file:
path: "{{ item }}"
state: absent
loop:
- /tmp/myfs.img
- /tmp/myfs
when: ansible_system in ('Linux')
...