summaryrefslogtreecommitdiffstats
path: root/debian/patches/0010-fix-facter.patch
blob: 943c2f67345679590adf0c1c8b1d6e65cf08a3bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Description: Fix facter when installed without puppet
Author: Brian Coca <brian.coca+git@gmail.com>
Origin: upstream, https://github.com/ansible/ansible/pull/80645/
Bug: https://github.com/ansible/ansible/issues/80496
Forwarded: not-needed
Reviewed-by: Lee Garrett <debian@rocketjump.eu>
Last-Update: 2023-11-10
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
diff --git a/changelogs/fragments/setup_facter_fix.yml b/changelogs/fragments/setup_facter_fix.yml
new file mode 100644
index 00000000000000..78a6b005a4abf2
--- /dev/null
+++ b/changelogs/fragments/setup_facter_fix.yml
@@ -0,0 +1,2 @@
+bugfixes:
+  - setup module (fact gathering) will now try to be smarter about different versions of facter emitting error when --puppet flag is used w/o puppet.
diff --git a/lib/ansible/module_utils/facts/other/facter.py b/lib/ansible/module_utils/facts/other/facter.py
index 3f83999d419d5c..9b6edc0b5ceaf9 100644
--- a/lib/ansible/module_utils/facts/other/facter.py
+++ b/lib/ansible/module_utils/facts/other/facter.py
@@ -1,27 +1,12 @@
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
+# Copyright (c) 2023 Ansible Project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
 
 from __future__ import (absolute_import, division, print_function)
 __metaclass__ = type
 
 import json
 
-import ansible.module_utils.compat.typing as t
-
 from ansible.module_utils.facts.namespace import PrefixFactNamespace
-
 from ansible.module_utils.facts.collector import BaseFactCollector
 
 
@@ -49,6 +34,12 @@ def run_facter(self, module, facter_path):
         # if facter is installed, and we can use --json because
         # ruby-json is ALSO installed, include facter data in the JSON
         rc, out, err = module.run_command(facter_path + " --puppet --json")
+
+        # for some versions of facter, --puppet returns an error if puppet is not present,
+        # try again w/o it, other errors should still appear and be sent back
+        if rc != 0:
+            rc, out, err = module.run_command(facter_path + " --json")
+
         return rc, out, err
 
     def get_facter_output(self, module):

From dace8abd19b1ef17d6534d881234e4771263dd1b Mon Sep 17 00:00:00 2001
From: Brian Coca <brian.coca+git@gmail.com>
Date: Wed, 26 Apr 2023 12:30:08 -0400
Subject: [PATCH 2/2] restore import

---
 lib/ansible/module_utils/facts/other/facter.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/ansible/module_utils/facts/other/facter.py b/lib/ansible/module_utils/facts/other/facter.py
index 9b6edc0b5ceaf9..063065251dd36e 100644
--- a/lib/ansible/module_utils/facts/other/facter.py
+++ b/lib/ansible/module_utils/facts/other/facter.py
@@ -6,6 +6,8 @@
 
 import json
 
+import ansible.module_utils.compat.typing as t
+
 from ansible.module_utils.facts.namespace import PrefixFactNamespace
 from ansible.module_utils.facts.collector import BaseFactCollector