summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2024-09-26 21:05:57 +0200
committerGitHub <noreply@github.com>2024-09-26 21:05:57 +0200
commit34f8f55d9e5a85d21207cc174f88eb2d62edd119 (patch)
tree2f40c3b38845ada74ee51ec76c02da37f3ccbe2e
parentpackage/dnf action plugins: better facts failure msg (#83995) (diff)
downloadansible-34f8f55d9e5a85d21207cc174f88eb2d62edd119.tar.xz
ansible-34f8f55d9e5a85d21207cc174f88eb2d62edd119.zip
facts: Skip path if the distribution path is directory (#84012)
* facts: Skip path if the distribution path is directory Skip path if the distribution path is directory instead of file. Handle exception raised while handling distribution path. Fixes: #84006 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> * Review requests --------- Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
-rw-r--r--changelogs/fragments/os_family.yml3
-rw-r--r--lib/ansible/module_utils/facts/system/distribution.py2
-rw-r--r--test/units/module_utils/facts/system/distribution/test_distribution_files.py17
3 files changed, 21 insertions, 1 deletions
diff --git a/changelogs/fragments/os_family.yml b/changelogs/fragments/os_family.yml
new file mode 100644
index 0000000000..7126a00c27
--- /dev/null
+++ b/changelogs/fragments/os_family.yml
@@ -0,0 +1,3 @@
+---
+bugfixes:
+ - facts - skip if distribution file path is directory, instead of raising error (https://github.com/ansible/ansible/issues/84006).
diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py
index 76f49b6ce8..7554ef1ae3 100644
--- a/lib/ansible/module_utils/facts/system/distribution.py
+++ b/lib/ansible/module_utils/facts/system/distribution.py
@@ -30,7 +30,7 @@ def get_uname(module, flags=('-v')):
def _file_exists(path, allow_empty=False):
# not finding the file, exit early
- if not os.path.exists(path):
+ if not os.path.isfile(path):
return False
# if just the path needs to exists (ie, it can be empty) we are done
diff --git a/test/units/module_utils/facts/system/distribution/test_distribution_files.py b/test/units/module_utils/facts/system/distribution/test_distribution_files.py
new file mode 100644
index 0000000000..af743604d6
--- /dev/null
+++ b/test/units/module_utils/facts/system/distribution/test_distribution_files.py
@@ -0,0 +1,17 @@
+# Copyright: Contributors to the Ansible project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import annotations
+
+import tempfile
+
+
+from ansible.module_utils.facts.system.distribution import DistributionFiles
+
+
+def test_distribution_files(mock_module):
+ d = DistributionFiles(mock_module)
+ temp_dir = tempfile.TemporaryDirectory()
+ dist_file, dist_file_content = d._get_dist_file_content(temp_dir.name)
+ assert not dist_file
+ assert dist_file_content is None