Compare commits

...

12 commits

Author SHA1 Message Date
mubashirusman
1a304d2fd3
Merge 6280bb8ec8 into ea6ef5c775 2025-07-28 10:40:02 +02:00
softwarefactory-project-zuul[bot]
ea6ef5c775
Merge pull request #665 from saito-hideki/pr/readme_20250728
Update README for release of Ansible Core 2.19

SUMMARY
README updated with the release of Ansible Core 2.19

https://docs.ansible.com/ansible/devel/roadmap/ROADMAP_2_19.html

ISSUE TYPE

Docs Pull Request

COMPONENT NAME

ansible.posix

ADDITIONAL INFORMATION
N/A
2025-07-28 08:38:22 +00:00
saito-hideki
9007e20b2f
README updated with the release of Ansible Core 2.19
* https://docs.ansible.com/ansible/devel/roadmap/ROADMAP_2_19.html

Signed-off-by: saito-hideki <saito@fgrep.org>
2025-07-28 17:12:02 +09:00
softwarefactory-project-zuul[bot]
508e3d920f
Merge pull request #666 from saito-hideki/pr/azp_update_matrix_20250728
[AZP][CI] Update AZP matrix to follow ansible-test changes

SUMMARY
Update AZP matrix to follow ansible-test changes

ansible/ansible/pull/85558
ansible/ansible/pull/85561
ansible/ansible/pull/85562

ISSUE TYPE

CI Pull Request

COMPONENT NAME

ansible.posix

ADDITIONAL INFORMATION
None
2025-07-28 06:32:06 +00:00
saito-hideki
18e023dd77
Update AZP matrix to follow ansible-test changes
* https://github.com/ansible/ansible/pull/85558
* https://github.com/ansible/ansible/pull/85561
* https://github.com/ansible/ansible/pull/85562

Signed-off-by: saito-hideki <saito@fgrep.org>
2025-07-28 14:59:14 +09: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
7 changed files with 122 additions and 30 deletions

View file

@ -137,8 +137,8 @@ stages:
parameters: parameters:
testFormat: devel/linux/{0}/1 testFormat: devel/linux/{0}/1
targets: targets:
- name: Fedora 41 - name: Fedora 42
test: fedora41 test: fedora42
- name: Ubuntu 22.04 - name: Ubuntu 22.04
test: ubuntu2204 test: ubuntu2204
- name: Ubuntu 24.04 - name: Ubuntu 24.04
@ -151,8 +151,8 @@ stages:
parameters: parameters:
testFormat: devel/linux/{0}/1 testFormat: devel/linux/{0}/1
targets: targets:
- name: Fedora 41 - name: Fedora 42
test: fedora41 test: fedora42
- name: Ubuntu 22.04 - name: Ubuntu 22.04
test: ubuntu2204 test: ubuntu2204
- name: Ubuntu 24.04 - name: Ubuntu 24.04
@ -226,10 +226,10 @@ stages:
targets: targets:
- name: RHEL 10.0 - name: RHEL 10.0
test: rhel/10.0 test: rhel/10.0
- name: RHEL 9.5 - name: RHEL 9.6
test: rhel/9.5 test: rhel/9.6
- name: FreeBSD 14.2 - name: FreeBSD 14.3
test: freebsd/14.2 test: freebsd/14.3
- name: FreeBSD 13.5 - name: FreeBSD 13.5
test: freebsd/13.5 test: freebsd/13.5
- stage: Remote_2_19 - stage: Remote_2_19
@ -242,10 +242,10 @@ stages:
targets: targets:
- name: RHEL 10.0 - name: RHEL 10.0
test: rhel/10.0 test: rhel/10.0
- name: RHEL 9.5 - name: RHEL 9.6
test: rhel/9.5 test: rhel/9.6
- name: FreeBSD 14.2 - name: FreeBSD 14.3
test: freebsd/14.2 test: freebsd/14.3
- name: FreeBSD 13.5 - name: FreeBSD 13.5
test: freebsd/13.5 test: freebsd/13.5
- stage: Remote_2_18 - stage: Remote_2_18
@ -258,8 +258,8 @@ stages:
targets: targets:
- name: RHEL 9.4 - name: RHEL 9.4
test: rhel/9.4 test: rhel/9.4
- name: FreeBSD 13.3 - name: FreeBSD 13.5
test: freebsd/13.3 test: freebsd/13.5
- stage: Remote_2_17 - stage: Remote_2_17
displayName: Remote 2.17 displayName: Remote 2.17
dependsOn: [] dependsOn: []
@ -270,8 +270,8 @@ stages:
targets: targets:
- name: RHEL 9.3 - name: RHEL 9.3
test: rhel/9.3 test: rhel/9.3
- name: FreeBSD 13.3 - name: FreeBSD 13.5
test: freebsd/13.3 test: freebsd/13.5
- stage: Remote_2_16 - stage: Remote_2_16
displayName: Remote 2.16 displayName: Remote 2.16
dependsOn: [] dependsOn: []

View file

@ -46,10 +46,10 @@ To upgrade the collection to the latest available version, run the following com
ansible-galaxy collection install ansible.posix --upgrade ansible-galaxy collection install ansible.posix --upgrade
``` ```
You can also install a specific version of the collection, for example, if you need to downgrade when something is broken in the latest version (please report an issue in this repository). Use the following syntax to install version 1.0.0: You can also install a specific version of the collection, for example, if you need to downgrade when something is broken in the latest version (please report an issue in this repository). Use the following syntax to install version 2.0.0:
```shell ```shell
ansible-galaxy collection install ansible.posix:==1.0.0 ansible-galaxy collection install ansible.posix:==2.0.0
``` ```
See [using Ansible collections](https://docs.ansible.com/ansible/devel/user_guide/collections_using.html) for more details. See [using Ansible collections](https://docs.ansible.com/ansible/devel/user_guide/collections_using.html) for more details.
@ -78,11 +78,10 @@ ansible-doc -t callback ansible.posix.profile_tasks
The following ansible-core versions have been tested with this collection: The following ansible-core versions have been tested with this collection:
- ansible-core 2.19 (devel) - ansible-core 2.20 (devel)
- ansible-core 2.18 (stable) * - ansible-core 2.19 (stable) *
- ansible-core 2.18 (stable)
- ansible-core 2.17 (stable) - ansible-core 2.17 (stable)
- ansible-core 2.16 (stable)
- ansible-core 2.15 (stable)
## Contributing ## Contributing

View file

@ -0,0 +1,3 @@
---
trivial:
- README - Update README to reflect Ansible Core 2.19 release.

View file

@ -0,0 +1,3 @@
---
trivial:
- AZP - Update AZP matrix to follow ansible-test changes.

View file

@ -108,6 +108,7 @@ import os
import platform import platform
import re import re
import tempfile import tempfile
import glob
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
@ -121,12 +122,24 @@ class SysctlModule(object):
# success or failure. # success or failure.
LANG_ENV = {'LANG': 'C', 'LC_ALL': 'C', 'LC_MESSAGES': 'C'} 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): def __init__(self, module):
self.module = module self.module = module
self.args = self.module.params self.args = self.module.params
self.sysctl_cmd = self.module.get_bin_path('sysctl', required=True) self.sysctl_cmd = self.module.get_bin_path('sysctl', required=True)
self.sysctl_file = self.args['sysctl_file'] 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.proc_value = None # current token value in proc fs
self.file_value = None # current token value in file self.file_value = None # current token value in file
@ -306,15 +319,22 @@ class SysctlModule(object):
# https://github.com/ansible/ansible/issues/58158 # https://github.com/ansible/ansible/issues/58158
return return
else: else:
# system supports reloading via the -p flag to sysctl, so we'll use that if self.system_Wide:
sysctl_args = [self.sysctl_cmd, '-p', self.sysctl_file] for sysctl_file in self.SYSCTL_DIRS:
if self.args['ignoreerrors']: for conf_file in glob.glob(sysctl_file):
sysctl_args.insert(1, '-e') 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): if rc != 0 or self._stderr_failed(err):
self.module.fail_json(msg="Failed to reload sysctl: %s" % to_native(out) + to_native(err)) self.module.fail_json(msg="Failed to reload sysctl: %s" % to_native(out) + to_native(err))
# ============================================================== # ==============================================================
# SYSCTL FILE MANAGEMENT # SYSCTL FILE MANAGEMENT
@ -401,7 +421,8 @@ def main():
reload=dict(default=True, type='bool'), reload=dict(default=True, type='bool'),
sysctl_set=dict(default=False, type='bool'), sysctl_set=dict(default=False, type='bool'),
ignoreerrors=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, supports_check_mode=True,
required_if=[('state', 'present', ['value'])], required_if=[('state', 'present', ['value'])],

View file

@ -1,3 +1,5 @@
needs/privileged
needs/root
destructive destructive
shippable/posix/group1 shippable/posix/group1
skip/aix skip/aix

View file

@ -230,6 +230,40 @@
that: that:
- sysctl_test4 is failed - 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 - name: Test on RHEL VMs
when: when:
- ansible_facts.virtualization_type != 'docker' - ansible_facts.virtualization_type != 'docker'
@ -366,3 +400,33 @@
that: that:
- stat_result.stat.islnk is defined and stat_result.stat.islnk - stat_result.stat.islnk is defined and stat_result.stat.islnk
- stat_result.stat.lnk_source == '/tmp/ansible_sysctl_test.conf' - 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"]