From aaacdb9d137a96cd35a5e10ff0a75932c742132f Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Wed, 27 May 2026 15:45:16 +0900 Subject: [PATCH] In FreeBSD, fail if loader.conf shall be reloaded. (#664) (#748) Fix #663 (cherry picked from commit 3c232a2429aaa9b49cae40bb3afa1a0ceb03c221) Co-authored-by: Vladimir Botka --- changelogs/fragments/freebsd_sysctl.yml | 3 +++ plugins/modules/sysctl.py | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 changelogs/fragments/freebsd_sysctl.yml diff --git a/changelogs/fragments/freebsd_sysctl.yml b/changelogs/fragments/freebsd_sysctl.yml new file mode 100644 index 0000000..1745b7f --- /dev/null +++ b/changelogs/fragments/freebsd_sysctl.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - sysctl - reload sysctl only if the sysctl file is ``/etc/sysctl.conf`` or ``/etc/sysctl.conf.local`` (https://github.com/ansible-collections/ansible.posix/issues/663). diff --git a/plugins/modules/sysctl.py b/plugins/modules/sysctl.py index ede962b..18499cb 100644 --- a/plugins/modules/sysctl.py +++ b/plugins/modules/sysctl.py @@ -44,6 +44,7 @@ options: - If V(true), performs a C(/sbin/sysctl -p) if the O(sysctl_file) is updated. If V(false), does not reload C(sysctl) even if the O(sysctl_file) is updated. + - For FreeBSD, can not be used with O(sysctl_file) other than C(/etc/sysctl.conf) or C(/etc/sysctl.conf.local). type: bool default: true sysctl_file: @@ -166,6 +167,11 @@ class SysctlModule(object): self.platform = platform.system().lower() + # system specific tests + freebsd_sysctl_files = ['/etc/sysctl.conf', '/etc/sysctl.conf.local'] + if self.platform == 'freebsd' and self.sysctl_file not in freebsd_sysctl_files and self.args['reload']: + self.module.fail_json(msg="%s can not be reloaded. Set reload=False." % self.sysctl_file) + # Whitespace is bad self.args['name'] = self.args['name'].strip() self.args['value'] = self._parse_value(self.args['value'])