Compare commits

...

11 commits

Author SHA1 Message Date
mubashirusman
4d285d147a
Merge 6280bb8ec8 into 1b8aeb03cb 2025-03-27 14:28:04 -07:00
Pavel Knoblokh
1b8aeb03cb
sysctl: Add custom sysctl file example (#606) 2025-03-26 19:21:08 -07:00
softwarefactory-project-zuul[bot]
ed3d322fd5
Merge pull request #617 from Akasurde/ci_fix
[CI] update test containers

SUMMARY
Signed-off-by: Abhijeet Kasurde Akasurde@redhat.com
ISSUE TYPE

Bugfix Pull Request

Reviewed-by: Matt Clay
2025-03-26 19:00:30 +00:00
Abhijeet Kasurde
d9f54eb9d4 [CI] update test containers
Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
2025-03-26 09:02:59 -07:00
MubashirUsman
6280bb8ec8 Add integration test for --system option 2024-11-03 23:21:39 +01:00
mubashirusman
3b79155e68
Merge branch 'ansible-collections:main' into main 2024-11-03 23:07:55 +01:00
mubashirusman
05724a097b
Merge branch 'ansible-collections:main' into main 2024-10-15 22:26:52 +02:00
MubashirUsman
7e1b76c46e write sysctl reverted 2024-05-19 17:47:12 +02:00
MubashirUsman
505a4aaa09 system_wide in defining module 2024-05-19 17:29:02 +02:00
MubashirUsman
d70d2aaaa7 read sysctl_dir files 2024-05-19 16:29:36 +02:00
MubashirUsman
806ff5c1a3 added sysctl_dirs variable and system_wide var 2024-05-19 13:54:43 +02:00
4 changed files with 113 additions and 21 deletions

View file

@ -122,14 +122,14 @@ stages:
parameters:
testFormat: devel/linux/{0}/1
targets:
- name: Fedora 40
test: fedora40
- name: Fedora 41
test: fedora41
- name: Ubuntu 22.04
test: ubuntu2204
- name: Ubuntu 24.04
test: ubuntu2404
- stage: Docker_2_18
displayName: Docker devel
displayName: Docker 2.18
dependsOn: []
jobs:
- template: templates/matrix.yml
@ -201,14 +201,14 @@ stages:
parameters:
testFormat: devel/{0}/1
targets:
- name: RHEL 9.4
test: rhel/9.4
- name: FreeBSD 14.1
test: freebsd/14.1
- name: FreeBSD 13.4
test: freebsd/13.4
- name: RHEL 9.5
test: rhel/9.5
- name: FreeBSD 14.2
test: freebsd/14.2
- name: FreeBSD 13.5
test: freebsd/13.5
- stage: Remote_2_18
displayName: Remote devel
displayName: Remote 2.18
dependsOn: []
jobs:
- template: templates/matrix.yml

View file

@ -80,6 +80,13 @@ EXAMPLES = r'''
sysctl_file: /tmp/test_sysctl.conf
reload: false
# Enable resource limits management in FreeBSD
- ansible.posix.sysctl:
name: kern.racct.enable
value: '1'
sysctl_file: /boot/loader.conf
reload: false
# Set ip forwarding on in /proc and verify token value with the sysctl command
- ansible.posix.sysctl:
name: net.ipv4.ip_forward
@ -101,6 +108,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 +122,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
@ -298,6 +318,13 @@ class SysctlModule(object):
# so return here and do not continue to the error processing below
# https://github.com/ansible/ansible/issues/58158
return
else:
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]
@ -394,7 +421,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'])],

View file

@ -230,6 +230,40 @@
that:
- sysctl_test4 is failed
##
## sysctl --system
##
- name: Set vm.swappiness to 10 with --system option
ansible.posix.sysctl:
name: vm.swappiness
value: 10
state: present
reload: false
sysctl_set: true
system: true
register: sysctl_system_test1
- name: Check with sysctl command
ansible.builtin.command: sysctl vm.swappiness
changed_when: false
register: sysctl_check_system1
- name: Debug sysctl_system_test1 sysctl_check_system1
ansible.builtin.debug:
var: item
verbosity: 1
with_items:
- "{{ sysctl_system_test1 }}"
- "{{ sysctl_check_system1 }}"
- name: Validate results for --system option
ansible.builtin.assert:
that:
- sysctl_system_test1 is changed
- sysctl_check_system1.stdout_lines == ["vm.swappiness = 10"]
- name: Test on RHEL VMs
when:
- ansible_facts.virtualization_type != 'docker'
@ -366,3 +400,33 @@
that:
- stat_result.stat.islnk is defined and stat_result.stat.islnk
- stat_result.stat.lnk_source == '/tmp/ansible_sysctl_test.conf'
# Test sysctl: --system
- name: Set vm.swappiness to 10 with --system option
ansible.posix.sysctl:
name: vm.swappiness
value: 10
state: present
reload: false
sysctl_set: true
system: true
register: sysctl_system_test1
- name: Check with sysctl command
ansible.builtin.command: sysctl vm.swappiness
changed_when: false
register: sysctl_check_system1
- name: Debug sysctl_system_test1 sysctl_check_system1
ansible.builtin.debug:
var: item
verbosity: 1
with_items:
- "{{ sysctl_system_test1 }}"
- "{{ sysctl_check_system1 }}"
- name: Validate results for --system option
ansible.builtin.assert:
that:
- sysctl_system_test1 is changed
- sysctl_check_system1.stdout_lines == ["vm.swappiness = 10"]

View file

@ -62,15 +62,15 @@ else
retry pip install "https://github.com/ansible/ansible/archive/stable-${ansible_version}.tar.gz" --disable-pip-version-check
fi
export ANSIBLE_COLLECTIONS_PATHS="${PWD}/../../../"
export ANSIBLE_COLLECTIONS_PATH="${PWD}/../../../"
# START: HACK install dependencies
if [ "${ansible_version}" == "2.9" ] || [ "${ansible_version}" == "2.10" ]; then
# Note: Since community.general 5.x, Ansible Core versions prior to 2.11 are not supported.
# So we need to use 4.8.1 for Ansible 2.9 and Ansible Engine 2.10.
retry git clone --depth=1 --single-branch -b 4.8.1 https://github.com/ansible-collections/community.general.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/general"
retry git clone --depth=1 --single-branch -b 4.8.1 https://github.com/ansible-collections/community.general.git "${ANSIBLE_COLLECTIONS_PATH}/ansible_collections/community/general"
else
retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.general.git "${ANSIBLE_COLLECTIONS_PATHS}/ansible_collections/community/general"
retry git clone --depth=1 --single-branch https://github.com/ansible-collections/community.general.git "${ANSIBLE_COLLECTIONS_PATH}/ansible_collections/community/general"
fi
# Note: we're installing with git to work around Galaxy being a huge PITA (https://github.com/ansible/galaxy/issues/2429)
# END: HACK