mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-11 15:15:26 +01:00
Merge pull request #196 from saito-hideki/issue/28
Modify boot option handling on Linux systems Reviewed-by: https://github.com/apps/ansible-zuul
This commit is contained in:
commit
9d4ae8b7e4
3 changed files with 79 additions and 9 deletions
4
changelogs/fragments/196_boot_opt_for_linux.yml
Normal file
4
changelogs/fragments/196_boot_opt_for_linux.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
minor_changes:
|
||||
- mount - Change behavior of ``boot`` option to set ``noauto`` on Linux nodes
|
||||
(https://github.com/ansible-collections/ansible.posix/issues/28).
|
||||
|
|
@ -93,7 +93,10 @@ options:
|
|||
boot:
|
||||
description:
|
||||
- Determines if the filesystem should be mounted on boot.
|
||||
- Only applies to Solaris systems.
|
||||
- Only applies to Solaris and Linux systems.
|
||||
- For Solaris systems, C(true) will set C(yes) as the value of mount at boot
|
||||
in I(/etc/vfstab).
|
||||
- For Linux systems, C(true) will add C(noauto) to mount options in I(/etc/fstab).
|
||||
type: bool
|
||||
default: yes
|
||||
backup:
|
||||
|
|
@ -169,6 +172,15 @@ EXAMPLES = r'''
|
|||
opts: rw,sync,hard,intr
|
||||
state: mounted
|
||||
fstype: nfs
|
||||
|
||||
- name: Mount NFS volumes with noauto according to boot option
|
||||
ansible.posix.mount:
|
||||
src: 192.168.1.100:/nfs/ssd/shared_data
|
||||
path: /mnt/shared_data
|
||||
opts: rw,sync,hard,intr
|
||||
boot: no
|
||||
state: mounted
|
||||
fstype: nfs
|
||||
'''
|
||||
|
||||
|
||||
|
|
@ -227,7 +239,7 @@ def _set_mount_save_old(module, args):
|
|||
old_lines = []
|
||||
exists = False
|
||||
changed = False
|
||||
escaped_args = dict([(k, _escape_fstab(v)) for k, v in iteritems(args)])
|
||||
escaped_args = dict([(k, _escape_fstab(v)) for k, v in iteritems(args) if k != 'warnings'])
|
||||
new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n'
|
||||
|
||||
if platform.system() == 'SunOS':
|
||||
|
|
@ -673,7 +685,8 @@ def main():
|
|||
opts='-',
|
||||
passno='-',
|
||||
fstab=module.params['fstab'],
|
||||
boot='yes' if module.params['boot'] else 'no'
|
||||
boot='yes' if module.params['boot'] else 'no',
|
||||
warnings=[]
|
||||
)
|
||||
if args['fstab'] is None:
|
||||
args['fstab'] = '/etc/vfstab'
|
||||
|
|
@ -683,7 +696,9 @@ def main():
|
|||
opts='defaults',
|
||||
dump='0',
|
||||
passno='0',
|
||||
fstab=module.params['fstab']
|
||||
fstab=module.params['fstab'],
|
||||
boot='yes',
|
||||
warnings=[]
|
||||
)
|
||||
if args['fstab'] is None:
|
||||
args['fstab'] = '/etc/fstab'
|
||||
|
|
@ -700,14 +715,27 @@ def main():
|
|||
linux_mounts = get_linux_mounts(module)
|
||||
|
||||
if linux_mounts is None:
|
||||
args['warnings'] = (
|
||||
'Cannot open file /proc/self/mountinfo. '
|
||||
'Bind mounts might be misinterpreted.')
|
||||
args['warnings'].append('Cannot open file /proc/self/mountinfo.'
|
||||
' Bind mounts might be misinterpreted.')
|
||||
|
||||
# Override defaults with user specified params
|
||||
for key in ('src', 'fstype', 'passno', 'opts', 'dump', 'fstab'):
|
||||
if module.params[key] is not None:
|
||||
args[key] = module.params[key]
|
||||
if platform.system().lower() == 'linux':
|
||||
# Linux has 'noauto' as mount opts to handle mount on boot
|
||||
# So boot option should manage 'noauto' in opts
|
||||
# TODO: We need to support other system like *BSD that 'noauto' option available
|
||||
opts = args['opts'].split(',')
|
||||
if 'noauto' in opts:
|
||||
args['warnings'].append("Ignore the 'boot' due to 'opts' contains 'noauto'.")
|
||||
elif not module.params['boot']:
|
||||
args['boot'] = 'no'
|
||||
if 'defaults' in opts:
|
||||
args['warnings'].append("Ignore the 'boot' due to 'opts' contains 'defaults'.")
|
||||
else:
|
||||
opts.append('noauto')
|
||||
args['opts'] = ','.join(opts)
|
||||
|
||||
# If fstab file does not exist, we first need to create it. This mainly
|
||||
# happens when fstab option is passed to the module.
|
||||
|
|
|
|||
|
|
@ -227,11 +227,13 @@
|
|||
- name: Block to test remounted option
|
||||
block:
|
||||
- name: Create empty file
|
||||
command: dd if=/dev/zero of=/tmp/myfs.img bs=1048576 count=20
|
||||
community.general.filesize:
|
||||
path: /tmp/myfs.img
|
||||
size: 20M
|
||||
when: ansible_system in ('Linux')
|
||||
- name: Format FS
|
||||
when: ansible_system in ('Linux')
|
||||
community.general.system.filesystem:
|
||||
community.general.filesystem:
|
||||
fstype: ext3
|
||||
dev: /tmp/myfs.img
|
||||
- name: Mount the FS for the first time
|
||||
|
|
@ -294,3 +296,39 @@
|
|||
- /tmp/myfs.img
|
||||
- /tmp/myfs
|
||||
when: ansible_system in ('Linux')
|
||||
|
||||
- name: Block to test boot option for Linux
|
||||
block:
|
||||
- name: Create empty file
|
||||
community.general.filesize:
|
||||
path: /tmp/myfs.img
|
||||
size: 20M
|
||||
- name: Format FS
|
||||
community.general.filesystem:
|
||||
fstype: ext3
|
||||
dev: /tmp/myfs.img
|
||||
- name: Mount the FS with noauto option
|
||||
mount:
|
||||
path: /tmp/myfs
|
||||
src: /tmp/myfs.img
|
||||
fstype: ext3
|
||||
state: mounted
|
||||
boot: no
|
||||
opts: rw,user,async
|
||||
register: mount_info
|
||||
- name: assert the mount without noauto was successful
|
||||
assert:
|
||||
that:
|
||||
- mount_info['opts'] == 'rw,user,async,noauto'
|
||||
- name: Unmount FS
|
||||
mount:
|
||||
path: /tmp/myfs
|
||||
state: absent
|
||||
- name: Remove the test FS
|
||||
file:
|
||||
path: '{{ item }}'
|
||||
state: absent
|
||||
loop:
|
||||
- /tmp/myfs.img
|
||||
- /tmp/myfs
|
||||
when: ansible_system in ('Linux')
|
||||
|
|
|
|||
Loading…
Reference in a new issue