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

pull/59287/head
Raul Mahiques 5 years ago committed by Martin Krizek
parent a752e2a467
commit fd2116e26a

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

@ -74,9 +74,12 @@ options:
- C(absent) specifies that the device mount's entry will be removed from - 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 I(fstab) and will also unmount the device and remove the mount
point. 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 type: str
required: true required: true
choices: [ absent, mounted, present, unmounted ] choices: [ absent, mounted, present, unmounted, remounted ]
fstab: fstab:
description: description:
- File to use instead of C(/etc/fstab). - File to use instead of C(/etc/fstab).
@ -597,7 +600,7 @@ def main():
passno=dict(type='str'), passno=dict(type='str'),
src=dict(type='path'), src=dict(type='path'),
backup=dict(type='bool', default=False), 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, supports_check_mode=True,
required_if=( required_if=(
@ -730,6 +733,14 @@ def main():
module.fail_json(msg="Error mounting %s: %s" % (name, msg)) module.fail_json(msg="Error mounting %s: %s" % (name, msg))
elif state == 'present': elif state == 'present':
name, changed = set_mount(module, args) 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: else:
module.fail_json(msg='Unexpected position reached') module.fail_json(msg='Unexpected position reached')

@ -276,3 +276,67 @@
- "' 0 0' in optional_fields_content.stdout" - "' 0 0' in optional_fields_content.stdout"
- "1 == optional_fields_content.stdout_lines | length" - "1 == optional_fields_content.stdout_lines | length"
when: ansible_system in ('Linux') 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')
...

Loading…
Cancel
Save