mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-11 15:15:26 +01:00
Copy and adjust changes from ansible/ansible#59530 (#14)
This commit is contained in:
parent
8a11a72e0c
commit
147caed10d
2 changed files with 56 additions and 3 deletions
|
|
@ -75,7 +75,11 @@ options:
|
||||||
point.
|
point.
|
||||||
- C(remounted) specifies that the device will be remounted for when you
|
- 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
|
want to force a refresh on the mount itself (added in 2.9). This will
|
||||||
always return changed=true.
|
always return changed=true. If I(opts) is set, the options will be
|
||||||
|
applied to the remount, but will not change I(fstab). Additionally,
|
||||||
|
if I(opts) is set, and the remount command fails, the module will
|
||||||
|
error to prevent unexpected mount changes. Try using C(mounted)
|
||||||
|
instead to work around this issue.
|
||||||
type: str
|
type: str
|
||||||
required: true
|
required: true
|
||||||
choices: [ absent, mounted, present, unmounted, remounted ]
|
choices: [ absent, mounted, present, unmounted, remounted ]
|
||||||
|
|
@ -103,6 +107,9 @@ options:
|
||||||
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.
|
||||||
|
- Using C(remounted) with I(opts) set may create unexpected results based on
|
||||||
|
the existing options already defined on mount, so care should be taken to
|
||||||
|
ensure that conflicting options are not present before hand.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
|
|
@ -135,6 +142,20 @@ EXAMPLES = r'''
|
||||||
path: /tmp/mnt-pnt
|
path: /tmp/mnt-pnt
|
||||||
state: unmounted
|
state: unmounted
|
||||||
|
|
||||||
|
- name: Remount a mounted volume
|
||||||
|
mount:
|
||||||
|
path: /tmp/mnt-pnt
|
||||||
|
state: remounted
|
||||||
|
|
||||||
|
# The following will not save changes to fstab, and only be temporary until
|
||||||
|
# a reboot, or until calling "state: unmounted" followed by "state: mounted"
|
||||||
|
# on the same "path"
|
||||||
|
- name: Remount a mounted volume and append exec to the existing options
|
||||||
|
mount:
|
||||||
|
path: /tmp
|
||||||
|
state: remounted
|
||||||
|
opts: exec
|
||||||
|
|
||||||
- name: Mount and bind a volume
|
- name: Mount and bind a volume
|
||||||
mount:
|
mount:
|
||||||
path: /system/new_volume/boot
|
path: /system/new_volume/boot
|
||||||
|
|
@ -426,9 +447,15 @@ def remount(module, args):
|
||||||
|
|
||||||
# Multiplatform remount opts
|
# Multiplatform remount opts
|
||||||
if platform.system().lower().endswith('bsd'):
|
if platform.system().lower().endswith('bsd'):
|
||||||
cmd += ['-u']
|
if module.params['state'] == 'remounted' and args['opts'] != 'defaults':
|
||||||
|
cmd += ['-u', '-o', args['opts']]
|
||||||
|
else:
|
||||||
|
cmd += ['-u']
|
||||||
else:
|
else:
|
||||||
cmd += ['-o', 'remount']
|
if module.params['state'] == 'remounted' and args['opts'] != 'defaults':
|
||||||
|
cmd += ['-o', 'remount,' + args['opts']]
|
||||||
|
else:
|
||||||
|
cmd += ['-o', 'remount']
|
||||||
|
|
||||||
if platform.system().lower() == 'openbsd':
|
if platform.system().lower() == 'openbsd':
|
||||||
# Use module.params['fstab'] here as args['fstab'] has been set to the
|
# Use module.params['fstab'] here as args['fstab'] has been set to the
|
||||||
|
|
@ -461,6 +488,16 @@ def remount(module, args):
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
msg = out + err
|
msg = out + err
|
||||||
|
|
||||||
|
if module.params['state'] == 'remounted' and args['opts'] != 'defaults':
|
||||||
|
module.fail_json(
|
||||||
|
msg=(
|
||||||
|
'Options were specified with remounted, but the remount '
|
||||||
|
'command failed. Failing in order to prevent an '
|
||||||
|
'unexpected mount result. Try replacing this command with '
|
||||||
|
'a "state: unmounted" followed by a "state: mounted" '
|
||||||
|
'using the full desired mount options instead.'))
|
||||||
|
|
||||||
rc, msg = umount(module, args['name'])
|
rc, msg = umount(module, args['name'])
|
||||||
|
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
|
|
|
||||||
|
|
@ -262,6 +262,22 @@
|
||||||
fail:
|
fail:
|
||||||
msg: Filesytem was not remounted, testing of the module failed!
|
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')
|
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')
|
||||||
|
- name: Remount filesystem with different opts using remounted option (Linux only)
|
||||||
|
mount:
|
||||||
|
path: /tmp/myfs
|
||||||
|
state: remounted
|
||||||
|
opts: rw,noexec
|
||||||
|
when: ansible_system == 'Linux'
|
||||||
|
- name: Get remounted options (Linux only)
|
||||||
|
shell: mount | grep myfs | grep -E -w 'noexec' | wc -l
|
||||||
|
register: remounted_options
|
||||||
|
when: ansible_system == 'Linux'
|
||||||
|
- name: Make sure the filesystem now has the new opts after using remounted (Linux only)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "'1' in remounted_options.stdout"
|
||||||
|
- "1 == remounted_options.stdout_lines | length"
|
||||||
|
when: ansible_system == 'Linux'
|
||||||
always:
|
always:
|
||||||
- name: Umount the test FS
|
- name: Umount the test FS
|
||||||
mount:
|
mount:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue