mirror of
https://github.com/ansible-collections/ansible.posix.git
synced 2026-05-11 20:12:14 +00:00
Compare commits
65 Commits
stable-2
...
cd6d33b1c0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd6d33b1c0 | ||
|
|
6da1331018 | ||
|
|
2d2df3989e | ||
|
|
df8413f3a0 | ||
|
|
f434c19e1e | ||
|
|
481de3d2dc | ||
|
|
ae90bac688 | ||
|
|
80290d8e06 | ||
|
|
560afe8217 | ||
|
|
571e80cdba | ||
|
|
9ce933f7d0 | ||
|
|
7f8505d693 | ||
|
|
2f5210f362 | ||
|
|
a91bbf6c04 | ||
|
|
ab8dfefd90 | ||
|
|
b96fad5e5b | ||
|
|
2d350e6073 | ||
|
|
ea6ef5c775 | ||
|
|
9007e20b2f | ||
|
|
508e3d920f | ||
|
|
18e023dd77 | ||
|
|
d3204df536 | ||
|
|
162e72182f | ||
|
|
1c1dd005c8 | ||
|
|
40c27e2bee | ||
|
|
c273ac2a01 | ||
|
|
f978998521 | ||
|
|
c319c856ed | ||
|
|
cdb442ea48 | ||
|
|
f977bffff2 | ||
|
|
dabaca4b70 | ||
|
|
26b9b1438d | ||
|
|
1994b2cf1c | ||
|
|
2f224e6a6a | ||
|
|
96ec2097cc | ||
|
|
7b9b1f4957 | ||
|
|
f0b5f039d3 | ||
|
|
5ceb40b600 | ||
|
|
2cec8cbed5 | ||
|
|
1b8aeb03cb | ||
|
|
eead50b287 | ||
|
|
4ff0e3aa13 | ||
|
|
979f00ce75 | ||
|
|
ed3d322fd5 | ||
|
|
d9f54eb9d4 | ||
|
|
7d8da00f79 | ||
|
|
f087d58cbe | ||
|
|
eb740e97d4 | ||
|
|
44a2151dbf | ||
|
|
83288b9020 | ||
|
|
4c6898ee6e | ||
|
|
f5eae12146 | ||
|
|
f632fad9d4 | ||
|
|
74edb72249 | ||
|
|
91129ed381 | ||
|
|
7b8d627552 | ||
|
|
6175a5028b | ||
|
|
8e34860d6c | ||
|
|
6280bb8ec8 | ||
|
|
3b79155e68 | ||
|
|
05724a097b | ||
|
|
7e1b76c46e | ||
|
|
505a4aaa09 | ||
|
|
d70d2aaaa7 | ||
|
|
806ff5c1a3 |
@@ -3,9 +3,23 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
# SPDX-FileCopyrightText: 2024, Ansible Project
|
# SPDX-FileCopyrightText: 2024, Ansible Project
|
||||||
|
|
||||||
|
# Use a more permissive profile due to documentation parsing issues
|
||||||
|
profile: min
|
||||||
|
|
||||||
skip_list:
|
skip_list:
|
||||||
- meta-runtime[unsupported-version] # This rule doesn't make any sense
|
- meta-runtime[unsupported-version] # This rule doesn't make any sense
|
||||||
- fqcn[deep] # This rule produces false positives for files in tests/unit/plugins/action/fixtures/
|
- fqcn[deep] # This rule produces false positives for files in tests/unit/plugins/action/fixtures/
|
||||||
- sanity[cannot-ignore] # This rule is skipped to keep backward compatibility with Python 2
|
- no-relative-paths # Temporary skip due to documentation parsing issue
|
||||||
|
- parser-error # Skip documentation parsing errors
|
||||||
|
- syntax-check # Skip syntax check issues in documentation
|
||||||
|
- load-failure # Skip module loading failures during documentation parsing
|
||||||
|
- args # Skip argument validation errors in documentation
|
||||||
|
|
||||||
exclude_paths:
|
exclude_paths:
|
||||||
- changelogs/
|
- changelogs/
|
||||||
|
|
||||||
|
# Enable specific rules we want to keep
|
||||||
|
enable_list:
|
||||||
|
- yaml
|
||||||
|
- name
|
||||||
|
- var-naming
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pool: Standard
|
|||||||
|
|
||||||
stages:
|
stages:
|
||||||
- stage: Sanity_devel
|
- stage: Sanity_devel
|
||||||
displayName: Ansible devel Sanity & Units & Lint
|
displayName: Ansible devel sanity
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
@@ -57,23 +57,8 @@ stages:
|
|||||||
test: units
|
test: units
|
||||||
- name: Lint
|
- name: Lint
|
||||||
test: lint
|
test: lint
|
||||||
- stage: Sanity_2_20
|
|
||||||
displayName: Ansible 2.20 Sanity & Units & Lint
|
|
||||||
dependsOn: []
|
|
||||||
jobs:
|
|
||||||
- template: templates/matrix.yml
|
|
||||||
parameters:
|
|
||||||
nameFormat: "{0}"
|
|
||||||
testFormat: 2.20/{0}
|
|
||||||
targets:
|
|
||||||
- name: Sanity
|
|
||||||
test: sanity
|
|
||||||
- name: Units
|
|
||||||
test: units
|
|
||||||
- name: Lint
|
|
||||||
test: lint
|
|
||||||
- stage: Sanity_2_19
|
- stage: Sanity_2_19
|
||||||
displayName: Ansible 2.19 Sanity & Units & Lint
|
displayName: Ansible 2.19 sanitay & Units & Lint
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
@@ -88,7 +73,7 @@ stages:
|
|||||||
- name: Lint
|
- name: Lint
|
||||||
test: lint
|
test: lint
|
||||||
- stage: Sanity_2_18
|
- stage: Sanity_2_18
|
||||||
displayName: Ansible 2.18 Sanity & Units & Lint
|
displayName: Ansible 2.18 sanity & Units & Lint
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
@@ -103,7 +88,7 @@ stages:
|
|||||||
- name: Lint
|
- name: Lint
|
||||||
test: lint
|
test: lint
|
||||||
- stage: Sanity_2_17
|
- stage: Sanity_2_17
|
||||||
displayName: Ansible 2.17 Sanity & Units & Lint
|
displayName: Ansible 2.17 sanity & Units & Lint
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
@@ -118,7 +103,7 @@ stages:
|
|||||||
- name: Lint
|
- name: Lint
|
||||||
test: lint
|
test: lint
|
||||||
- stage: Sanity_2_16
|
- stage: Sanity_2_16
|
||||||
displayName: Ansible 2.16 Sanity & Units & Lint
|
displayName: Ansible 2.16 sanity & Units & Lint
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
jobs:
|
jobs:
|
||||||
- template: templates/matrix.yml
|
- template: templates/matrix.yml
|
||||||
@@ -130,8 +115,6 @@ stages:
|
|||||||
test: sanity
|
test: sanity
|
||||||
- name: Units
|
- name: Units
|
||||||
test: units
|
test: units
|
||||||
- name: Lint
|
|
||||||
test: lint
|
|
||||||
## Docker
|
## Docker
|
||||||
- stage: Docker_devel
|
- stage: Docker_devel
|
||||||
displayName: Docker devel
|
displayName: Docker devel
|
||||||
@@ -147,20 +130,6 @@ stages:
|
|||||||
test: ubuntu2204
|
test: ubuntu2204
|
||||||
- name: Ubuntu 24.04
|
- name: Ubuntu 24.04
|
||||||
test: ubuntu2404
|
test: ubuntu2404
|
||||||
- stage: Docker_2_20
|
|
||||||
displayName: Docker 2.20
|
|
||||||
dependsOn: []
|
|
||||||
jobs:
|
|
||||||
- template: templates/matrix.yml
|
|
||||||
parameters:
|
|
||||||
testFormat: 2.20/linux/{0}/1
|
|
||||||
targets:
|
|
||||||
- name: Fedora 42
|
|
||||||
test: fedora42
|
|
||||||
- name: Ubuntu 22.04
|
|
||||||
test: ubuntu2204
|
|
||||||
- name: Ubuntu 24.04
|
|
||||||
test: ubuntu2404
|
|
||||||
- stage: Docker_2_19
|
- stage: Docker_2_19
|
||||||
displayName: Docker 2.19
|
displayName: Docker 2.19
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
@@ -233,22 +202,6 @@ stages:
|
|||||||
test: freebsd/14.3
|
test: freebsd/14.3
|
||||||
- name: FreeBSD 13.5
|
- name: FreeBSD 13.5
|
||||||
test: freebsd/13.5
|
test: freebsd/13.5
|
||||||
- stage: Remote_2_20
|
|
||||||
displayName: Remote 2.20
|
|
||||||
dependsOn: []
|
|
||||||
jobs:
|
|
||||||
- template: templates/matrix.yml
|
|
||||||
parameters:
|
|
||||||
testFormat: 2.20/{0}/1
|
|
||||||
targets:
|
|
||||||
- name: RHEL 10.0
|
|
||||||
test: rhel/10.0
|
|
||||||
- name: RHEL 9.6
|
|
||||||
test: rhel/9.6
|
|
||||||
- name: FreeBSD 14.3
|
|
||||||
test: freebsd/14.3
|
|
||||||
- name: FreeBSD 13.5
|
|
||||||
test: freebsd/13.5
|
|
||||||
- stage: Remote_2_19
|
- stage: Remote_2_19
|
||||||
displayName: Remote 2.19
|
displayName: Remote 2.19
|
||||||
dependsOn: []
|
dependsOn: []
|
||||||
@@ -273,8 +226,6 @@ stages:
|
|||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.18/{0}/1
|
testFormat: 2.18/{0}/1
|
||||||
targets:
|
targets:
|
||||||
- name: RHEL 10.0
|
|
||||||
test: rhel/10.0
|
|
||||||
- name: RHEL 9.4
|
- name: RHEL 9.4
|
||||||
test: rhel/9.4
|
test: rhel/9.4
|
||||||
- name: FreeBSD 13.5
|
- name: FreeBSD 13.5
|
||||||
@@ -287,9 +238,8 @@ stages:
|
|||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.17/{0}/1
|
testFormat: 2.17/{0}/1
|
||||||
targets:
|
targets:
|
||||||
# 2.17 remote target doesn't have RHEL 9 image
|
- name: RHEL 9.3
|
||||||
- name: RHEL 10.0
|
test: rhel/9.3
|
||||||
test: rhel/10.0
|
|
||||||
- name: FreeBSD 13.5
|
- name: FreeBSD 13.5
|
||||||
test: freebsd/13.5
|
test: freebsd/13.5
|
||||||
- stage: Remote_2_16
|
- stage: Remote_2_16
|
||||||
@@ -300,9 +250,10 @@ stages:
|
|||||||
parameters:
|
parameters:
|
||||||
testFormat: 2.16/{0}/1
|
testFormat: 2.16/{0}/1
|
||||||
targets:
|
targets:
|
||||||
# 2.16 remote target only has RHEL 9.6 image
|
- name: RHEL 8.8
|
||||||
- name: RHEL 9.6
|
test: rhel/8.8
|
||||||
test: rhel/9.6
|
- name: RHEL 9.2
|
||||||
|
test: rhel/9.2
|
||||||
|
|
||||||
## Finally
|
## Finally
|
||||||
|
|
||||||
@@ -321,9 +272,6 @@ stages:
|
|||||||
- Sanity_2_19
|
- Sanity_2_19
|
||||||
- Remote_2_19
|
- Remote_2_19
|
||||||
- Docker_2_19
|
- Docker_2_19
|
||||||
- Sanity_2_20
|
|
||||||
- Remote_2_20
|
|
||||||
- Docker_2_20
|
|
||||||
- Sanity_devel
|
- Sanity_devel
|
||||||
- Remote_devel
|
- Remote_devel
|
||||||
- Docker_devel
|
- Docker_devel
|
||||||
|
|||||||
@@ -4,27 +4,6 @@ ansible.posix Release Notes
|
|||||||
|
|
||||||
.. contents:: Topics
|
.. contents:: Topics
|
||||||
|
|
||||||
v2.1.0
|
|
||||||
======
|
|
||||||
|
|
||||||
Release Summary
|
|
||||||
---------------
|
|
||||||
|
|
||||||
This is the minor release of the ``ansible.posix`` collection.
|
|
||||||
This changelog contains all changes to the modules and plugins
|
|
||||||
in the stable-2 branch that have been added after the release of
|
|
||||||
``ansible.posix`` 2.0.0
|
|
||||||
|
|
||||||
Minor Changes
|
|
||||||
-------------
|
|
||||||
|
|
||||||
- profile_tasks and profile_roles callback plugins - avoid deleted/deprecated callback functions, instead use modern interface that was introduced a longer time ago (https://github.com/ansible-collections/ansible.posix/issues/650).
|
|
||||||
|
|
||||||
Bugfixes
|
|
||||||
--------
|
|
||||||
|
|
||||||
- ansible.posix.cgroup_perf_recap - fixes json module load path (https://github.com/ansible-collections/ansible.posix/issues/630).
|
|
||||||
|
|
||||||
v2.0.0
|
v2.0.0
|
||||||
======
|
======
|
||||||
|
|
||||||
|
|||||||
@@ -490,25 +490,3 @@ releases:
|
|||||||
- 597_remove_fstab_comment_on_updating.yml
|
- 597_remove_fstab_comment_on_updating.yml
|
||||||
- 598_icmp_block_inversion.yml
|
- 598_icmp_block_inversion.yml
|
||||||
release_date: '2024-12-04'
|
release_date: '2024-12-04'
|
||||||
2.1.0:
|
|
||||||
changes:
|
|
||||||
bugfixes:
|
|
||||||
- ansible.posix.cgroup_perf_recap - fixes json module load path (https://github.com/ansible-collections/ansible.posix/issues/630).
|
|
||||||
minor_changes:
|
|
||||||
- profile_tasks and profile_roles callback plugins - avoid deleted/deprecated
|
|
||||||
callback functions, instead use modern interface that was introduced a longer
|
|
||||||
time ago (https://github.com/ansible-collections/ansible.posix/issues/650).
|
|
||||||
release_summary: 'This is the minor release of the ``ansible.posix`` collection.
|
|
||||||
|
|
||||||
This changelog contains all changes to the modules and plugins
|
|
||||||
|
|
||||||
in the stable-2 branch that have been added after the release of
|
|
||||||
|
|
||||||
``ansible.posix`` 2.0.0'
|
|
||||||
fragments:
|
|
||||||
- 2.1.0.yml
|
|
||||||
- 631_fixes_module_path.yml
|
|
||||||
- 642_ci_add_rhel10.yml
|
|
||||||
- 650-profile_tasks_roles.yml
|
|
||||||
- 654_ci_bump_core_version.yml
|
|
||||||
release_date: '2025-07-16'
|
|
||||||
|
|||||||
2
changelogs/fragments/603_bump_version_3.yml
Normal file
2
changelogs/fragments/603_bump_version_3.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
trivial:
|
||||||
|
- Bump version to 3.0.0 for the next release (https://github.com/ansible-collections/ansible.posix/issues/603).
|
||||||
2
changelogs/fragments/618_ci_remove_ubuntu2004.yml
Normal file
2
changelogs/fragments/618_ci_remove_ubuntu2004.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
trivial:
|
||||||
|
- Remove ubuntu20.04 from CI tests (https://github.com/ansible-collections/ansible.posix/issues/612).
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- profile_tasks - Add option to provide a different date/time format (https://github.com/ansible-collections/ansible.posix/issues/279).
|
||||||
6
changelogs/fragments/631_fixes_module_path.yml
Normal file
6
changelogs/fragments/631_fixes_module_path.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- ansible.posix.cgroup_perf_recap - fixes json module load path (https://github.com/ansible-collections/ansible.posix/issues/630).
|
||||||
|
trivial:
|
||||||
|
- ansible.posix.seboolean - remove unnecessary condition from seboolean integration tests (https://github.com/ansible-collections/ansible.posix/issues/630).
|
||||||
|
- ansible.posix.selinux - optimize conditions for selinux integration tests (https://github.com/ansible-collections/ansible.posix/issues/630).
|
||||||
2
changelogs/fragments/642_ci_add_rhel10.yml
Normal file
2
changelogs/fragments/642_ci_add_rhel10.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
trivial:
|
||||||
|
- Add Red Hat Enterprise Linux 10.0 to the CI matrix (https://github.com/ansible-collections/ansible.posix/issues/642).
|
||||||
2
changelogs/fragments/650-profile_tasks_roles.yml
Normal file
2
changelogs/fragments/650-profile_tasks_roles.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
minor_changes:
|
||||||
|
- "profile_tasks and profile_roles callback plugins - avoid deleted/deprecated callback functions, instead use modern interface that was introduced a longer time ago (https://github.com/ansible-collections/ansible.posix/issues/650)."
|
||||||
3
changelogs/fragments/654_ci_bump_core_version.yml
Normal file
3
changelogs/fragments/654_ci_bump_core_version.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
trivial:
|
||||||
|
- Bump ansible-core version to 2.20 of devel branch and add 2.19 to CI
|
||||||
3
changelogs/fragments/670-deprecations.yml
Normal file
3
changelogs/fragments/670-deprecations.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
bugfixes:
|
||||||
|
- "firewalld_info - stop returning warnings as return values; this has been deprecated by ansible-core (https://github.com/ansible-collections/ansible.posix/pull/670)."
|
||||||
|
- "mount - stop returning warnings as return values; this has been deprecated by ansible-core (https://github.com/ansible-collections/ansible.posix/pull/670)."
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
trivial:
|
|
||||||
- Updatng AZP CI matrix to ignore ansible-bad-import-from on six(https://github.com/ansible-collections/ansible.posix/pull/682).
|
|
||||||
- Skipped sanity[cannot-ignore] to keep backward compatibility with Python2.
|
|
||||||
- Consolidate all ansible-lint option locations into .ansible-lint file.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
trivial:
|
|
||||||
- AZP - Update AZP matrix to follow ansible-test changes.
|
|
||||||
- Add ignore file for Ansible Core 2.21.
|
|
||||||
- Remove ignore lines for ansible-bad-import-from in 2.20 sanity tests.
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
namespace: ansible
|
namespace: ansible
|
||||||
name: posix
|
name: posix
|
||||||
version: 2.1.0
|
version: 3.0.0
|
||||||
readme: README.md
|
readme: README.md
|
||||||
authors:
|
authors:
|
||||||
- Ansible (github.com/ansible)
|
- Ansible (github.com/ansible)
|
||||||
|
|||||||
@@ -52,6 +52,17 @@ DOCUMENTATION = '''
|
|||||||
- section: callback_profile_tasks
|
- section: callback_profile_tasks
|
||||||
key: summary_only
|
key: summary_only
|
||||||
version_added: 1.5.0
|
version_added: 1.5.0
|
||||||
|
datetime_format:
|
||||||
|
description:
|
||||||
|
- Datetime format, as expected by the C(strftime) and C(strptime) methods.
|
||||||
|
An C(iso8601) alias will be translated to C('%Y-%m-%dT%H:%M:%S.%f') if that datetime standard wants to be used.
|
||||||
|
default: '%A %d %B %Y %H:%M:%S %z'
|
||||||
|
env:
|
||||||
|
- name: PROFILE_TASKS_DATETIME_FORMAT
|
||||||
|
ini:
|
||||||
|
- section: callback_profile_tasks
|
||||||
|
key: datetime_format
|
||||||
|
version_added: 3.0.0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
@@ -72,14 +83,15 @@ sample output: >
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import time
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from ansible.module_utils.six.moves import reduce
|
from ansible.module_utils.six.moves import reduce
|
||||||
from ansible.plugins.callback import CallbackBase
|
from ansible.plugins.callback import CallbackBase
|
||||||
|
|
||||||
|
|
||||||
# define start time
|
# define start time
|
||||||
t0 = tn = time.time()
|
dt0 = dtn = datetime.now().astimezone()
|
||||||
|
|
||||||
|
|
||||||
def secondsToStr(t):
|
def secondsToStr(t):
|
||||||
@@ -104,17 +116,18 @@ def filled(msg, fchar="*"):
|
|||||||
|
|
||||||
def timestamp(self):
|
def timestamp(self):
|
||||||
if self.current is not None:
|
if self.current is not None:
|
||||||
elapsed = time.time() - self.stats[self.current]['started']
|
elapsed = (datetime.now().astimezone() - self.stats[self.current]['started']).total_seconds()
|
||||||
self.stats[self.current]['elapsed'] += elapsed
|
self.stats[self.current]['elapsed'] += elapsed
|
||||||
|
|
||||||
|
|
||||||
def tasktime():
|
def tasktime(self):
|
||||||
global tn
|
global dtn
|
||||||
time_current = time.strftime('%A %d %B %Y %H:%M:%S %z')
|
cdtn = datetime.now().astimezone()
|
||||||
time_elapsed = secondsToStr(time.time() - tn)
|
datetime_current = cdtn.strftime(self.datetime_format)
|
||||||
time_total_elapsed = secondsToStr(time.time() - t0)
|
time_elapsed = secondsToStr((cdtn - dtn).total_seconds())
|
||||||
tn = time.time()
|
time_total_elapsed = secondsToStr((cdtn - dt0).total_seconds())
|
||||||
return filled('%s (%s)%s%s' % (time_current, time_elapsed, ' ' * 7, time_total_elapsed))
|
dtn = cdtn
|
||||||
|
return filled('%s (%s)%s%s' % (datetime_current, time_elapsed, ' ' * 7, time_total_elapsed))
|
||||||
|
|
||||||
|
|
||||||
class CallbackModule(CallbackBase):
|
class CallbackModule(CallbackBase):
|
||||||
@@ -134,6 +147,7 @@ class CallbackModule(CallbackBase):
|
|||||||
self.sort_order = None
|
self.sort_order = None
|
||||||
self.summary_only = None
|
self.summary_only = None
|
||||||
self.task_output_limit = None
|
self.task_output_limit = None
|
||||||
|
self.datetime_format = None
|
||||||
|
|
||||||
super(CallbackModule, self).__init__()
|
super(CallbackModule, self).__init__()
|
||||||
|
|
||||||
@@ -159,9 +173,14 @@ class CallbackModule(CallbackBase):
|
|||||||
else:
|
else:
|
||||||
self.task_output_limit = int(self.task_output_limit)
|
self.task_output_limit = int(self.task_output_limit)
|
||||||
|
|
||||||
|
self.datetime_format = self.get_option('datetime_format')
|
||||||
|
if self.datetime_format is not None:
|
||||||
|
if self.datetime_format == 'iso8601':
|
||||||
|
self.datetime_format = '%Y-%m-%dT%H:%M:%S.%f'
|
||||||
|
|
||||||
def _display_tasktime(self):
|
def _display_tasktime(self):
|
||||||
if not self.summary_only:
|
if not self.summary_only:
|
||||||
self._display.display(tasktime())
|
self._display.display(tasktime(self))
|
||||||
|
|
||||||
def _record_task(self, task):
|
def _record_task(self, task):
|
||||||
"""
|
"""
|
||||||
@@ -176,10 +195,11 @@ class CallbackModule(CallbackBase):
|
|||||||
# with the same UUID is executed when `serial` is specified in a playbook.
|
# with the same UUID is executed when `serial` is specified in a playbook.
|
||||||
# elapsed: Elapsed time since the first serialized task was started
|
# elapsed: Elapsed time since the first serialized task was started
|
||||||
self.current = task._uuid
|
self.current = task._uuid
|
||||||
|
dtn = datetime.now().astimezone()
|
||||||
if self.current not in self.stats:
|
if self.current not in self.stats:
|
||||||
self.stats[self.current] = {'started': time.time(), 'elapsed': 0.0, 'name': task.get_name()}
|
self.stats[self.current] = {'started': dtn, 'elapsed': 0.0, 'name': task.get_name()}
|
||||||
else:
|
else:
|
||||||
self.stats[self.current]['started'] = time.time()
|
self.stats[self.current]['started'] = dtn
|
||||||
if self._display.verbosity >= 2:
|
if self._display.verbosity >= 2:
|
||||||
self.stats[self.current]['path'] = task.get_path()
|
self.stats[self.current]['path'] = task.get_path()
|
||||||
|
|
||||||
@@ -193,7 +213,7 @@ class CallbackModule(CallbackBase):
|
|||||||
# Align summary report header with other callback plugin summary
|
# Align summary report header with other callback plugin summary
|
||||||
self._display.banner("TASKS RECAP")
|
self._display.banner("TASKS RECAP")
|
||||||
|
|
||||||
self._display.display(tasktime())
|
self._display.display(tasktime(self))
|
||||||
self._display.display(filled("", fchar="="))
|
self._display.display(filled("", fchar="="))
|
||||||
|
|
||||||
timestamp(self)
|
timestamp(self)
|
||||||
|
|||||||
@@ -319,7 +319,6 @@ def main():
|
|||||||
active_zones=module.params['active_zones'],
|
active_zones=module.params['active_zones'],
|
||||||
collected_zones=list(),
|
collected_zones=list(),
|
||||||
undefined_zones=list(),
|
undefined_zones=list(),
|
||||||
warnings=list(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Exit with failure message if requirements modules are not installed.
|
# Exit with failure message if requirements modules are not installed.
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ def _set_mount_save_old(module, args):
|
|||||||
old_lines = []
|
old_lines = []
|
||||||
exists = False
|
exists = False
|
||||||
changed = False
|
changed = False
|
||||||
escaped_args = dict([(k, _escape_fstab(v)) for k, v in iteritems(args) if k != 'warnings'])
|
escaped_args = dict([(k, _escape_fstab(v)) for k, v in iteritems(args)])
|
||||||
new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n'
|
new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n'
|
||||||
|
|
||||||
if platform.system() == 'SunOS':
|
if platform.system() == 'SunOS':
|
||||||
@@ -804,7 +804,6 @@ def main():
|
|||||||
passno='-',
|
passno='-',
|
||||||
fstab=module.params['fstab'],
|
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:
|
if args['fstab'] is None:
|
||||||
args['fstab'] = '/etc/vfstab'
|
args['fstab'] = '/etc/vfstab'
|
||||||
@@ -816,7 +815,6 @@ def main():
|
|||||||
passno='0',
|
passno='0',
|
||||||
fstab=module.params['fstab'],
|
fstab=module.params['fstab'],
|
||||||
boot='yes',
|
boot='yes',
|
||||||
warnings=[]
|
|
||||||
)
|
)
|
||||||
if args['fstab'] is None:
|
if args['fstab'] is None:
|
||||||
args['fstab'] = '/etc/fstab'
|
args['fstab'] = '/etc/fstab'
|
||||||
@@ -834,8 +832,7 @@ def main():
|
|||||||
linux_mounts = get_linux_mounts(module)
|
linux_mounts = get_linux_mounts(module)
|
||||||
|
|
||||||
if linux_mounts is None:
|
if linux_mounts is None:
|
||||||
args['warnings'].append('Cannot open file /proc/self/mountinfo.'
|
module.warn('Cannot open file /proc/self/mountinfo. Bind mounts might be misinterpreted.')
|
||||||
' Bind mounts might be misinterpreted.')
|
|
||||||
|
|
||||||
# Override defaults with user specified params
|
# Override defaults with user specified params
|
||||||
for key in ('src', 'fstype', 'passno', 'opts', 'dump', 'fstab'):
|
for key in ('src', 'fstype', 'passno', 'opts', 'dump', 'fstab'):
|
||||||
@@ -847,7 +844,7 @@ def main():
|
|||||||
# specified in 'opts', mount module will ignore 'boot'.
|
# specified in 'opts', mount module will ignore 'boot'.
|
||||||
opts = args['opts'].split(',')
|
opts = args['opts'].split(',')
|
||||||
if module.params['boot'] and 'noauto' in opts:
|
if module.params['boot'] and 'noauto' in opts:
|
||||||
args['warnings'].append("Ignore the 'boot' due to 'opts' contains 'noauto'.")
|
module.warn("Ignore the 'boot' due to 'opts' contains 'noauto'.")
|
||||||
elif not module.params['boot']:
|
elif not module.params['boot']:
|
||||||
args['boot'] = 'no'
|
args['boot'] = 'no'
|
||||||
opts.append('noauto')
|
opts.append('noauto')
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ options:
|
|||||||
- Verify token value with the sysctl command and set with C(-w) if necessary.
|
- Verify token value with the sysctl command and set with C(-w) if necessary.
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
|
system_wide:
|
||||||
|
description:
|
||||||
|
- If V(true), uses C(sysctl --system) behavior to reload all sysctl configuration files.
|
||||||
|
- This will reload configuration from C(/etc/sysctl.d/*.conf), C(/run/sysctl.d/*.conf),
|
||||||
|
C(/usr/local/lib/sysctl.d/*.conf), C(/usr/lib/sysctl.d/*.conf), C(/lib/sysctl.d/*.conf),
|
||||||
|
and C(/etc/sysctl.conf) in that order.
|
||||||
|
- If V(false), only reloads the specific sysctl file defined by O(sysctl_file).
|
||||||
|
- Only applies when O(reload) is V(true).
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
author:
|
author:
|
||||||
- David CHANIAL (@davixx)
|
- David CHANIAL (@davixx)
|
||||||
'''
|
'''
|
||||||
@@ -80,6 +90,13 @@ EXAMPLES = r'''
|
|||||||
sysctl_file: /tmp/test_sysctl.conf
|
sysctl_file: /tmp/test_sysctl.conf
|
||||||
reload: false
|
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
|
# Set ip forwarding on in /proc and verify token value with the sysctl command
|
||||||
- ansible.posix.sysctl:
|
- ansible.posix.sysctl:
|
||||||
name: net.ipv4.ip_forward
|
name: net.ipv4.ip_forward
|
||||||
@@ -93,6 +110,14 @@ EXAMPLES = r'''
|
|||||||
sysctl_set: true
|
sysctl_set: true
|
||||||
state: present
|
state: present
|
||||||
reload: true
|
reload: true
|
||||||
|
|
||||||
|
# Set vm.swappiness and reload all system sysctl configuration files (equivalent to sysctl --system)
|
||||||
|
- ansible.posix.sysctl:
|
||||||
|
name: vm.swappiness
|
||||||
|
value: '10'
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: true
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# ==============================================================
|
# ==============================================================
|
||||||
@@ -101,6 +126,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
|
||||||
@@ -114,17 +140,30 @@ 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
|
||||||
self.file_lines = [] # all lines in the file
|
self.file_lines = [] # all lines in the file
|
||||||
self.file_values = {} # dict of token values
|
self.file_values = {} # dict of token values
|
||||||
|
self.system_wide_file_value = None # current token value from system-wide files
|
||||||
|
|
||||||
self.changed = False # will change occur
|
self.changed = False # will change occur
|
||||||
self.set_proc = False # does sysctl need to set value
|
self.set_proc = False # does sysctl need to set value
|
||||||
@@ -154,19 +193,36 @@ class SysctlModule(object):
|
|||||||
if thisname not in self.file_values:
|
if thisname not in self.file_values:
|
||||||
self.file_values[thisname] = None
|
self.file_values[thisname] = None
|
||||||
|
|
||||||
|
# if system_wide is enabled, also check system-wide configuration
|
||||||
|
if self.system_wide:
|
||||||
|
system_wide_values = self.read_system_wide_sysctl_files()
|
||||||
|
# If the value exists in system-wide config, use that for comparison
|
||||||
|
if thisname in system_wide_values:
|
||||||
|
self.system_wide_file_value = system_wide_values[thisname]
|
||||||
|
else:
|
||||||
|
self.system_wide_file_value = None
|
||||||
|
else:
|
||||||
|
self.system_wide_file_value = None
|
||||||
|
|
||||||
# update file contents with desired token/value
|
# update file contents with desired token/value
|
||||||
self.fix_lines()
|
self.fix_lines()
|
||||||
|
|
||||||
# what do we need to do now?
|
# what do we need to do now?
|
||||||
if self.file_values[thisname] is None and self.args['state'] == "present":
|
# Determine the effective current value (system-wide takes precedence if enabled)
|
||||||
|
if self.system_wide and self.system_wide_file_value is not None:
|
||||||
|
current_file_value = self.system_wide_file_value
|
||||||
|
else:
|
||||||
|
current_file_value = self.file_values[thisname]
|
||||||
|
|
||||||
|
if current_file_value is None and self.args['state'] == "present":
|
||||||
self.changed = True
|
self.changed = True
|
||||||
self.write_file = True
|
self.write_file = True
|
||||||
elif self.file_values[thisname] is None and self.args['state'] == "absent":
|
elif current_file_value is None and self.args['state'] == "absent":
|
||||||
self.changed = False
|
self.changed = False
|
||||||
elif self.file_values[thisname] and self.args['state'] == "absent":
|
elif current_file_value and self.args['state'] == "absent":
|
||||||
self.changed = True
|
self.changed = True
|
||||||
self.write_file = True
|
self.write_file = True
|
||||||
elif self.file_values[thisname] != self.args['value']:
|
elif current_file_value != self.args['value']:
|
||||||
self.changed = True
|
self.changed = True
|
||||||
self.write_file = True
|
self.write_file = True
|
||||||
# with reload=yes we should check if the current system values are
|
# with reload=yes we should check if the current system values are
|
||||||
@@ -299,15 +355,25 @@ 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')
|
sysctl_args = [self.sysctl_cmd, '-p', conf_file]
|
||||||
|
if self.args['ignoreerrors']:
|
||||||
|
sysctl_args.insert(1, '-e')
|
||||||
|
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))
|
||||||
|
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
|
||||||
@@ -337,6 +403,35 @@ class SysctlModule(object):
|
|||||||
v = v.strip()
|
v = v.strip()
|
||||||
self.file_values[k] = v.strip()
|
self.file_values[k] = v.strip()
|
||||||
|
|
||||||
|
# Get the token value from all system-wide sysctl files
|
||||||
|
def read_system_wide_sysctl_files(self):
|
||||||
|
"""Read all system-wide sysctl configuration files when system_wide=True"""
|
||||||
|
system_values = {}
|
||||||
|
|
||||||
|
for sysctl_pattern in self.SYSCTL_DIRS:
|
||||||
|
for conf_file in glob.glob(sysctl_pattern):
|
||||||
|
if os.path.isfile(conf_file):
|
||||||
|
try:
|
||||||
|
with open(conf_file, "r") as read_file:
|
||||||
|
lines = read_file.readlines()
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
# don't split empty lines or comments or line without equal sign
|
||||||
|
if not line or line.startswith(("#", ";")) or "=" not in line:
|
||||||
|
continue
|
||||||
|
|
||||||
|
k, v = line.split('=', 1)
|
||||||
|
k = k.strip()
|
||||||
|
v = v.strip()
|
||||||
|
# Later files override earlier ones (mimicking sysctl --system behavior)
|
||||||
|
system_values[k] = v.strip()
|
||||||
|
except IOError:
|
||||||
|
# Skip files that can't be read
|
||||||
|
continue
|
||||||
|
|
||||||
|
return system_values
|
||||||
|
|
||||||
# Fix the value in the sysctl file content
|
# Fix the value in the sysctl file content
|
||||||
def fix_lines(self):
|
def fix_lines(self):
|
||||||
checked = []
|
checked = []
|
||||||
@@ -394,7 +489,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'])],
|
||||||
|
|||||||
@@ -140,8 +140,8 @@
|
|||||||
ansible.posix.sysctl:
|
ansible.posix.sysctl:
|
||||||
name: test.invalid
|
name: test.invalid
|
||||||
value: 1
|
value: 1
|
||||||
register: sysctl_test3
|
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
register: sysctl_test3
|
||||||
|
|
||||||
- name: Debug sysctl_test3
|
- name: Debug sysctl_test3
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
@@ -230,6 +230,91 @@
|
|||||||
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_wide: 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
|
||||||
|
- "'10' in sysctl_check_system1.stdout"
|
||||||
|
|
||||||
|
# Test system_wide with reload=true
|
||||||
|
- name: Set vm.dirty_ratio to 20 with system_wide and reload=true
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.dirty_ratio
|
||||||
|
value: 20
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: true
|
||||||
|
register: sysctl_system_reload_test
|
||||||
|
|
||||||
|
- name: Check vm.dirty_ratio value
|
||||||
|
ansible.builtin.command: sysctl -n vm.dirty_ratio
|
||||||
|
changed_when: false
|
||||||
|
register: sysctl_check_dirty_ratio
|
||||||
|
|
||||||
|
- name: Validate system_wide with reload
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_reload_test is changed
|
||||||
|
- sysctl_check_dirty_ratio.stdout == "20"
|
||||||
|
|
||||||
|
# Test system_wide=false behavior (default)
|
||||||
|
- name: Create custom sysctl file for testing
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: |
|
||||||
|
# Custom sysctl test file
|
||||||
|
vm.dirty_background_ratio=5
|
||||||
|
dest: "{{ output_dir_test }}/custom_sysctl.conf"
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Set vm.dirty_background_ratio with system_wide=false
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.dirty_background_ratio
|
||||||
|
value: 10
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: false
|
||||||
|
sysctl_file: "{{ output_dir_test }}/custom_sysctl.conf"
|
||||||
|
register: sysctl_system_false_test
|
||||||
|
|
||||||
|
- name: Check custom sysctl file content
|
||||||
|
ansible.builtin.command: cat {{ output_dir_test }}/custom_sysctl.conf
|
||||||
|
changed_when: false
|
||||||
|
register: custom_sysctl_content
|
||||||
|
|
||||||
|
- name: Validate system_wide=false behavior
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_false_test is changed
|
||||||
|
- "'vm.dirty_background_ratio=10' in custom_sysctl_content.stdout"
|
||||||
|
|
||||||
|
|
||||||
- name: Test on RHEL VMs
|
- name: Test on RHEL VMs
|
||||||
when:
|
when:
|
||||||
- ansible_facts.virtualization_type != 'docker'
|
- ansible_facts.virtualization_type != 'docker'
|
||||||
@@ -366,3 +451,36 @@
|
|||||||
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_wide: 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: Include system_wide specific tests
|
||||||
|
ansible.builtin.include_tasks: system_wide_tests.yml
|
||||||
|
|||||||
203
tests/integration/targets/sysctl/tasks/system_wide_tests.yml
Normal file
203
tests/integration/targets/sysctl/tasks/system_wide_tests.yml
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
---
|
||||||
|
# Additional tests specifically for system_wide parameter functionality
|
||||||
|
|
||||||
|
- name: Test system_wide parameter basic functionality
|
||||||
|
block:
|
||||||
|
# Test system_wide with a simple sysctl parameter
|
||||||
|
- name: Set vm.swappiness with system_wide=true (first time)
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.swappiness
|
||||||
|
value: 35
|
||||||
|
state: present
|
||||||
|
reload: false
|
||||||
|
system_wide: true
|
||||||
|
register: sysctl_system_wide_first_test
|
||||||
|
|
||||||
|
- name: Debug first test result
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: sysctl_system_wide_first_test
|
||||||
|
|
||||||
|
- name: Set vm.swappiness with system_wide=true (second time - should not change)
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.swappiness
|
||||||
|
value: 35
|
||||||
|
state: present
|
||||||
|
reload: false
|
||||||
|
system_wide: true
|
||||||
|
register: sysctl_system_wide_second_test
|
||||||
|
|
||||||
|
- name: Debug second test result
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: sysctl_system_wide_second_test
|
||||||
|
|
||||||
|
- name: Validate system_wide basic functionality
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_wide_first_test is changed
|
||||||
|
- sysctl_system_wide_second_test is not changed
|
||||||
|
|
||||||
|
# Test system_wide with reload=true
|
||||||
|
- name: Set vm.dirty_expire_centisecs with system_wide=true and reload
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.dirty_expire_centisecs
|
||||||
|
value: 3000
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: true
|
||||||
|
register: sysctl_system_wide_reload_test
|
||||||
|
|
||||||
|
- name: Check vm.dirty_expire_centisecs value
|
||||||
|
ansible.builtin.command: sysctl -n vm.dirty_expire_centisecs
|
||||||
|
changed_when: false
|
||||||
|
register: sysctl_check_dirty_expire
|
||||||
|
|
||||||
|
- name: Validate system_wide with reload=true
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_wide_reload_test is changed
|
||||||
|
- sysctl_check_dirty_expire.stdout == "3000"
|
||||||
|
|
||||||
|
# Test system_wide=false behavior (default)
|
||||||
|
- name: Create custom sysctl file for testing system_wide=false
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: |
|
||||||
|
# Custom sysctl test file
|
||||||
|
vm.dirty_background_ratio=5
|
||||||
|
dest: "{{ output_dir_test }}/custom_sysctl.conf"
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Set vm.dirty_background_ratio with system_wide=false
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.dirty_background_ratio
|
||||||
|
value: 10
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: false
|
||||||
|
sysctl_file: "{{ output_dir_test }}/custom_sysctl.conf"
|
||||||
|
register: sysctl_system_false_test
|
||||||
|
|
||||||
|
- name: Check custom sysctl file content
|
||||||
|
ansible.builtin.command: cat {{ output_dir_test }}/custom_sysctl.conf
|
||||||
|
changed_when: false
|
||||||
|
register: custom_sysctl_content
|
||||||
|
|
||||||
|
- name: Validate system_wide=false behavior
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_false_test is changed
|
||||||
|
- "'vm.dirty_background_ratio=10' in custom_sysctl_content.stdout"
|
||||||
|
|
||||||
|
# Test system_wide with check mode
|
||||||
|
- name: Test system_wide in check mode
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.swappiness
|
||||||
|
value: 25
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: true
|
||||||
|
check_mode: true
|
||||||
|
register: sysctl_system_wide_check_mode
|
||||||
|
|
||||||
|
- name: Validate check mode works with system_wide
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_wide_check_mode is changed
|
||||||
|
|
||||||
|
# Test system_wide with missing directories (should not fail)
|
||||||
|
- name: Test system_wide with potentially missing directories
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.overcommit_memory
|
||||||
|
value: 1
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: true
|
||||||
|
ignoreerrors: true
|
||||||
|
register: sysctl_system_wide_missing_dirs
|
||||||
|
|
||||||
|
- name: Validate system_wide handles missing directories
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_wide_missing_dirs is not failed
|
||||||
|
|
||||||
|
- name: Test system_wide with multiple configuration files (RHEL/CentOS only)
|
||||||
|
when:
|
||||||
|
- ansible_facts.os_family == 'RedHat'
|
||||||
|
- ansible_facts.virtualization_type != 'docker'
|
||||||
|
block:
|
||||||
|
# Test that system_wide processes multiple configuration files
|
||||||
|
- name: Create test sysctl.d file
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: |
|
||||||
|
# Test system-wide sysctl reload
|
||||||
|
vm.dirty_writeback_centisecs=500
|
||||||
|
dest: /etc/sysctl.d/99-ansible-test.conf
|
||||||
|
mode: "0644"
|
||||||
|
backup: true
|
||||||
|
register: test_sysctl_file
|
||||||
|
|
||||||
|
- name: Apply setting with system_wide to test multiple file processing
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.overcommit_memory
|
||||||
|
value: 1
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: true
|
||||||
|
register: sysctl_multifile_test
|
||||||
|
|
||||||
|
- name: Verify both settings are applied
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
sysctl -n vm.dirty_writeback_centisecs
|
||||||
|
sysctl -n vm.overcommit_memory
|
||||||
|
changed_when: false
|
||||||
|
register: sysctl_multifile_check
|
||||||
|
|
||||||
|
- name: Validate multiple file processing
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_multifile_test is changed
|
||||||
|
- "'500' in sysctl_multifile_check.stdout"
|
||||||
|
- "'1' in sysctl_multifile_check.stdout"
|
||||||
|
|
||||||
|
- name: Cleanup test sysctl.d file
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/sysctl.d/99-ansible-test.conf
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Test system_wide parameter combinations
|
||||||
|
block:
|
||||||
|
# Test system_wide with sysctl_set
|
||||||
|
- name: Test system_wide with sysctl_set=true
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.swappiness
|
||||||
|
value: 15
|
||||||
|
state: present
|
||||||
|
reload: true
|
||||||
|
system_wide: true
|
||||||
|
sysctl_set: true
|
||||||
|
register: sysctl_system_wide_set_test
|
||||||
|
|
||||||
|
- name: Check vm.swappiness value after system_wide + sysctl_set
|
||||||
|
ansible.builtin.command: sysctl -n vm.swappiness
|
||||||
|
changed_when: false
|
||||||
|
register: sysctl_check_swappiness_set
|
||||||
|
|
||||||
|
- name: Validate system_wide with sysctl_set
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_wide_set_test is changed
|
||||||
|
- sysctl_check_swappiness_set.stdout == "15"
|
||||||
|
|
||||||
|
# Test system_wide with reload=false (should not trigger system reload)
|
||||||
|
- name: Test system_wide with reload=false
|
||||||
|
ansible.posix.sysctl:
|
||||||
|
name: vm.dirty_ratio
|
||||||
|
value: 25
|
||||||
|
state: present
|
||||||
|
reload: false
|
||||||
|
system_wide: true
|
||||||
|
register: sysctl_system_wide_no_reload
|
||||||
|
|
||||||
|
- name: Validate system_wide with reload=false
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- sysctl_system_wide_no_reload is changed
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
tests/utils/shippable/timing.py shebang
|
|
||||||
plugins/action/synchronize.py pylint:ansible-bad-import-from
|
|
||||||
plugins/callback/cgroup_perf_recap.py pylint:ansible-bad-import-from
|
|
||||||
plugins/modules/mount.py pylint:ansible-bad-import-from
|
|
||||||
plugins/modules/sysctl.py pylint:ansible-bad-import-from
|
|
||||||
plugins/shell/csh.py pylint:ansible-bad-import-from
|
|
||||||
plugins/shell/fish.py pylint:ansible-bad-import-from
|
|
||||||
tests/unit/mock/procenv.py pylint:ansible-bad-import-from
|
|
||||||
tests/unit/mock/yaml_helper.py pylint:ansible-bad-import-from
|
|
||||||
tests/unit/modules/conftest.py pylint:ansible-bad-import-from
|
|
||||||
@@ -9,5 +9,6 @@ command -v ansible
|
|||||||
pip install --upgrade --user pip
|
pip install --upgrade --user pip
|
||||||
pip install --upgrade --user ansible-lint
|
pip install --upgrade --user ansible-lint
|
||||||
|
|
||||||
# To specify additional options, you can specify them into .ansible-lint file.
|
PATH="${PATH/\~/${HOME}}" ansible-lint \
|
||||||
PATH="${PATH/\~/${HOME}}" ansible-lint
|
--exclude changelogs/ \
|
||||||
|
--profile=production
|
||||||
|
|||||||
Reference in New Issue
Block a user