From 2cf823a2ad3c0cd3313699f40b8a77c82dd5ac8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Tue, 21 May 2024 21:14:31 +0000 Subject: [PATCH 01/11] add systemd full_version and ensure version is integer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- changelogs/fragments/fix_systemd_facts.yml | 3 +++ lib/ansible/module_utils/facts/system/systemd.py | 5 ++++- .../targets/systemd/tasks/test_systemd_version.yml | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/fix_systemd_facts.yml diff --git a/changelogs/fragments/fix_systemd_facts.yml b/changelogs/fragments/fix_systemd_facts.yml new file mode 100644 index 00000000000..f024143bed3 --- /dev/null +++ b/changelogs/fragments/fix_systemd_facts.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - facts - add systemd full_version and ensure version is integer diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index 154dc73fb2a..ada5d7b4a41 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -42,6 +42,9 @@ class SystemdFactCollector(BaseFactCollector): systemd_facts["systemd"] = {} systemd_facts["systemd"]["features"] = str(stdout.split("\n")[1]) - systemd_facts["systemd"]["version"] = int(stdout.split(" ")[1]) + systemd_facts["systemd"]["full_version"] = str( + (stdout.split(" ")[2]).split(")")[0][1:], + ) + systemd_facts["systemd"]["version"] = int(stdout.split(" ")[1][:3]) return systemd_facts diff --git a/test/integration/targets/systemd/tasks/test_systemd_version.yml b/test/integration/targets/systemd/tasks/test_systemd_version.yml index 2b2fae167c8..76fe9bcad9d 100644 --- a/test/integration/targets/systemd/tasks/test_systemd_version.yml +++ b/test/integration/targets/systemd/tasks/test_systemd_version.yml @@ -8,4 +8,6 @@ that: - ansible_systemd.version | int - ansible_systemd.version is match('^[1-9][0-9][0-9]$') + - ansible_systemd.full_version | string + - ansible_systemd.full_version is match('^[1-9][0-9][0-9](.|-|~)') - ansible_systemd.features | regex_search('(\\+|-)(PAM|AUDIT)') From 6d3fb8689601c927915102f82f2f0ce8644921a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Fri, 24 May 2024 09:14:28 +0000 Subject: [PATCH 02/11] change type depending on stdout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- lib/ansible/module_utils/facts/system/systemd.py | 7 ++++++- .../targets/systemd/tasks/test_systemd_version.yml | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index ada5d7b4a41..324dc3ca1b0 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -40,11 +40,16 @@ class SystemdFactCollector(BaseFactCollector): if rc != 0: return systemd_facts + systemd_version = str(stdout.split(" ")[1]) + systemd_facts["systemd"] = {} systemd_facts["systemd"]["features"] = str(stdout.split("\n")[1]) systemd_facts["systemd"]["full_version"] = str( (stdout.split(" ")[2]).split(")")[0][1:], ) - systemd_facts["systemd"]["version"] = int(stdout.split(" ")[1][:3]) + try: + systemd_facts["systemd"]["version"] = int(systemd_version) + except ValueError: + systemd_facts["systemd"]["version"] = str(systemd_version) return systemd_facts diff --git a/test/integration/targets/systemd/tasks/test_systemd_version.yml b/test/integration/targets/systemd/tasks/test_systemd_version.yml index 76fe9bcad9d..31e234a8c13 100644 --- a/test/integration/targets/systemd/tasks/test_systemd_version.yml +++ b/test/integration/targets/systemd/tasks/test_systemd_version.yml @@ -1,13 +1,12 @@ --- -- name: Show Gathered Facts +- name: Show systemd facts ansible.builtin.debug: msg: "{{ ansible_systemd }}" - name: Assert the systemd version fact ansible.builtin.assert: that: - - ansible_systemd.version | int - - ansible_systemd.version is match('^[1-9][0-9][0-9]$') + - ansible_systemd.version is match('^[1-9][0-9][0-9]') - ansible_systemd.full_version | string - ansible_systemd.full_version is match('^[1-9][0-9][0-9](.|-|~)') - ansible_systemd.features | regex_search('(\\+|-)(PAM|AUDIT)') From aec5a6bf9a36dab7367cb7403ca1a292ff848221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Sat, 28 Dec 2024 00:28:23 +0000 Subject: [PATCH 03/11] add newline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- lib/ansible/module_utils/facts/system/systemd.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index a151e0092c7..3679396c87d 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -51,4 +51,5 @@ class SystemdFactCollector(BaseFactCollector): except ValueError: systemd_facts["systemd"]["version"] = str(systemd_version) - return systemd_facts \ No newline at end of file + return systemd_facts + From 704941628b30729a94c2cbbfaa60288d1a406e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Sat, 28 Dec 2024 00:35:03 +0000 Subject: [PATCH 04/11] return indent level MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- lib/ansible/module_utils/facts/system/systemd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index 3679396c87d..aaaafe6ab97 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -51,5 +51,5 @@ class SystemdFactCollector(BaseFactCollector): except ValueError: systemd_facts["systemd"]["version"] = str(systemd_version) - return systemd_facts + return systemd_facts From 6231a810b35bbb50c17e21ad0fa94e8052f78e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Tue, 21 Jan 2025 17:23:12 +0100 Subject: [PATCH 05/11] Update lib/ansible/module_utils/facts/system/systemd.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) --- lib/ansible/module_utils/facts/system/systemd.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index aaaafe6ab97..417be131980 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -52,4 +52,3 @@ class SystemdFactCollector(BaseFactCollector): systemd_facts["systemd"]["version"] = str(systemd_version) return systemd_facts - From 5f7069736cb455f946964046757cda86a65f7e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Tue, 21 Jan 2025 17:23:31 +0100 Subject: [PATCH 06/11] Update lib/ansible/module_utils/facts/system/systemd.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) --- lib/ansible/module_utils/facts/system/systemd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index 417be131980..c1f2ee91cff 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -44,7 +44,7 @@ class SystemdFactCollector(BaseFactCollector): systemd_facts["systemd"] = {} systemd_facts["systemd"]["features"] = str(stdout.split("\n")[1]) systemd_facts["systemd"]["full_version"] = str( - (stdout.split(" ")[2]).split(")")[0][1:], + stdout.split(" ")[2].split(")")[0][1:], ) try: systemd_facts["systemd"]["version"] = int(systemd_version) From 89892efa894b240ae9693f50a7a30b69f262eb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Tue, 21 Jan 2025 17:24:09 +0100 Subject: [PATCH 07/11] Update lib/ansible/module_utils/facts/system/systemd.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) --- lib/ansible/module_utils/facts/system/systemd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index c1f2ee91cff..04dfbd27d14 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -42,7 +42,7 @@ class SystemdFactCollector(BaseFactCollector): systemd_version = str(stdout.split(" ")[1]) systemd_facts["systemd"] = {} - systemd_facts["systemd"]["features"] = str(stdout.split("\n")[1]) + systemd_facts["systemd"]["features"] = stdout.split("\n")[1] systemd_facts["systemd"]["full_version"] = str( stdout.split(" ")[2].split(")")[0][1:], ) From ad22e4707ecfd42f5315507fa509b4055279668a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Tue, 21 Jan 2025 17:24:45 +0100 Subject: [PATCH 08/11] Update lib/ansible/module_utils/facts/system/systemd.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) --- lib/ansible/module_utils/facts/system/systemd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index 04dfbd27d14..a69b73c2c42 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -39,7 +39,7 @@ class SystemdFactCollector(BaseFactCollector): if rc != 0: return systemd_facts - systemd_version = str(stdout.split(" ")[1]) + systemd_version = stdout.split(" ")[1] systemd_facts["systemd"] = {} systemd_facts["systemd"]["features"] = stdout.split("\n")[1] From a165473a870e0ac6080185a624f3ae5f07090c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Tue, 21 Jan 2025 17:43:16 +0100 Subject: [PATCH 09/11] Update lib/ansible/module_utils/facts/system/systemd.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) --- lib/ansible/module_utils/facts/system/systemd.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index a69b73c2c42..11f7af27fd4 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -46,9 +46,9 @@ class SystemdFactCollector(BaseFactCollector): systemd_facts["systemd"]["full_version"] = str( stdout.split(" ")[2].split(")")[0][1:], ) - try: - systemd_facts["systemd"]["version"] = int(systemd_version) - except ValueError: - systemd_facts["systemd"]["version"] = str(systemd_version) + with contextlib.suppress(ValueError): + systemd_version = int(systemd_version) + + systemd_facts["systemd"]["version"] = systemd_version return systemd_facts From d426ee4aaf9d66d0c152c3a4028cb9198381512e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Tue, 21 Jan 2025 16:46:02 +0000 Subject: [PATCH 10/11] import contextlib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- lib/ansible/module_utils/facts/system/systemd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ansible/module_utils/facts/system/systemd.py b/lib/ansible/module_utils/facts/system/systemd.py index 11f7af27fd4..6b9ae8129c8 100644 --- a/lib/ansible/module_utils/facts/system/systemd.py +++ b/lib/ansible/module_utils/facts/system/systemd.py @@ -18,6 +18,7 @@ from __future__ import annotations import ansible.module_utils.compat.typing as t +import contextlib from ansible.module_utils.facts.collector import BaseFactCollector from ansible.module_utils.facts.system.service_mgr import ServiceMgrFactCollector From 6982b99de027e01616c97400f589d765506b2669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 26 May 2025 21:52:01 +0000 Subject: [PATCH 11/11] support integer full_version and test is full_version is a str MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- .../targets/systemd/tasks/test_systemd_version.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/targets/systemd/tasks/test_systemd_version.yml b/test/integration/targets/systemd/tasks/test_systemd_version.yml index 0dead8c7d4c..c38df01e620 100644 --- a/test/integration/targets/systemd/tasks/test_systemd_version.yml +++ b/test/integration/targets/systemd/tasks/test_systemd_version.yml @@ -8,6 +8,6 @@ that: - ansible_systemd.version | int > 0 - ansible_systemd.version is match('^[1-9][0-9][0-9]$') - - ansible_systemd.full_version | string - - ansible_systemd.full_version is match('^[1-9][0-9][0-9](.|-|~)') - - ansible_systemd.features | regex_search('(\\+|-)(PAM|AUDIT)') is not none \ No newline at end of file + - ansible_systemd.features | regex_search('(\\+|-)(PAM|AUDIT)') is not none + - ansible_systemd.full_version is match('^[1-9][0-9][0-9](.|-|~)|^[1-9][0-9][0-9]$') + - (ansible_systemd.full_version | type_debug == 'AnsibleUnsafeText' or ansible_systemd.full_version | type_debug == 'str')