mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-01-12 07:35:31 +01:00
Compare commits
7 commits
2f18007ea2
...
c5bb74005c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5bb74005c | ||
|
|
9cf2d8cc48 | ||
|
|
2041e7f918 | ||
|
|
7e1b76c46e | ||
|
|
505a4aaa09 | ||
|
|
d70d2aaaa7 | ||
|
|
806ff5c1a3 |
4 changed files with 53 additions and 13 deletions
3
changelogs/fragments/365-boot-linux.yml
Normal file
3
changelogs/fragments/365-boot-linux.yml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
bugfixes:
|
||||
- mount - Handle ``boot`` option on Linux, NetBSD and OpenBSD correctly (https://github.com/ansible-collections/ansible.posix/issues/364).
|
||||
|
|
@ -850,11 +850,8 @@ def main():
|
|||
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)
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ import os
|
|||
import platform
|
||||
import re
|
||||
import tempfile
|
||||
import glob
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six import string_types
|
||||
|
|
@ -114,12 +115,24 @@ class SysctlModule(object):
|
|||
# success or failure.
|
||||
LANG_ENV = {'LANG': 'C', 'LC_ALL': 'C', 'LC_MESSAGES': 'C'}
|
||||
|
||||
# We define a variable to keep all the directories to be read, equivalent to
|
||||
# (/sbin/sysctl --system) option
|
||||
SYSCTL_DIRS = [
|
||||
'/etc/sysctl.d/*.conf',
|
||||
'/run/sysctl.d/*.conf',
|
||||
'/usr/local/lib/sysctl.d/*.conf',
|
||||
'/usr/lib/sysctl.d/*.conf',
|
||||
'/lib/sysctl.d/*.conf',
|
||||
'/etc/sysctl.conf'
|
||||
]
|
||||
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.args = self.module.params
|
||||
|
||||
self.sysctl_cmd = self.module.get_bin_path('sysctl', required=True)
|
||||
self.sysctl_file = self.args['sysctl_file']
|
||||
self.system_Wide = self.args['system_Wide']
|
||||
|
||||
self.proc_value = None # current token value in proc fs
|
||||
self.file_value = None # current token value in file
|
||||
|
|
@ -299,15 +312,22 @@ class SysctlModule(object):
|
|||
# https://github.com/ansible/ansible/issues/58158
|
||||
return
|
||||
else:
|
||||
# system supports reloading via the -p flag to sysctl, so we'll use that
|
||||
sysctl_args = [self.sysctl_cmd, '-p', self.sysctl_file]
|
||||
if self.args['ignoreerrors']:
|
||||
sysctl_args.insert(1, '-e')
|
||||
if self.system_Wide:
|
||||
for sysctl_file in self.SYSCTL_DIRS:
|
||||
for conf_file in glob.glob(sysctl_file):
|
||||
rc, out, err = self.module.run_command([self.sysctl_cmd, '-p', conf_file], environ_update=self.LANG_ENV)
|
||||
if rc != 0 or self._stderr_failed(err):
|
||||
self.module.fail_json(msg="Failed to reload sysctl: %s" % to_native(out) + to_native(err))
|
||||
else:
|
||||
# system supports reloading via the -p flag to sysctl, so we'll use that
|
||||
sysctl_args = [self.sysctl_cmd, '-p', self.sysctl_file]
|
||||
if self.args['ignoreerrors']:
|
||||
sysctl_args.insert(1, '-e')
|
||||
|
||||
rc, out, err = self.module.run_command(sysctl_args, environ_update=self.LANG_ENV)
|
||||
rc, out, err = self.module.run_command(sysctl_args, environ_update=self.LANG_ENV)
|
||||
|
||||
if rc != 0 or self._stderr_failed(err):
|
||||
self.module.fail_json(msg="Failed to reload sysctl: %s" % to_native(out) + to_native(err))
|
||||
if rc != 0 or self._stderr_failed(err):
|
||||
self.module.fail_json(msg="Failed to reload sysctl: %s" % to_native(out) + to_native(err))
|
||||
|
||||
# ==============================================================
|
||||
# SYSCTL FILE MANAGEMENT
|
||||
|
|
@ -394,7 +414,8 @@ def main():
|
|||
reload=dict(default=True, type='bool'),
|
||||
sysctl_set=dict(default=False, type='bool'),
|
||||
ignoreerrors=dict(default=False, type='bool'),
|
||||
sysctl_file=dict(default='/etc/sysctl.conf', type='path')
|
||||
sysctl_file=dict(default='/etc/sysctl.conf', type='path'),
|
||||
system_wide=dict(default=False, type='bool'), # system_wide parameter
|
||||
),
|
||||
supports_check_mode=True,
|
||||
required_if=[('state', 'present', ['value'])],
|
||||
|
|
|
|||
|
|
@ -472,6 +472,25 @@
|
|||
path: /tmp/myfs
|
||||
state: absent
|
||||
|
||||
- name: Mount the FS with noauto option and defaults
|
||||
ansible.posix.mount:
|
||||
path: /tmp/myfs
|
||||
src: /tmp/myfs.img
|
||||
fstype: ext3
|
||||
state: mounted
|
||||
boot: false
|
||||
register: mount_info
|
||||
|
||||
- name: Assert the mount without noauto was successful
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'noauto' in mount_info['opts'].split(',')"
|
||||
|
||||
- name: Unmount FS
|
||||
ansible.posix.mount:
|
||||
path: /tmp/myfs
|
||||
state: absent
|
||||
|
||||
- name: Remove the test FS
|
||||
ansible.builtin.file:
|
||||
path: '{{ item }}'
|
||||
|
|
|
|||
Loading…
Reference in a new issue