Package: ansible-core
Version: 2.14.3-1
Severity: normal

Dear Maintainer,

i installed ansible-core and facter 4.3.0-2 in bookworm.  when testing
i found that the facts from facter were not being included by the
setup module:

% ansible -b localhost -m ansible.builtin.setup -a 'filter=facter_*'
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | SUCCESS => {
    "ansible_facts": {},
    "changed": false
}

this issue has appeared upstream and was resolved by:
setup module, retry facter to handle --puppet errors by bcoca · Pull Request 
#80645 · ansible/ansible · GitHub
https://github.com/ansible/ansible/pull/80645

i was eventually able to build an updated version of bookworm's
ansible-core .deb including commit id 4b0d014.  this task was made
more difficult by the current FTBFS status of ansible-core but the
patch allowed ansible.builtin.setup to include facts from facter:

% ansible -b localhost -m ansible.builtin.setup -a 'filter=facter_*'
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | SUCCESS => {
    "ansible_facts": {
        "facter_disks": {
            "sda": {
[...]
        "facter_timezone": "UTC",
        "facter_virtual": "physical"
    },
    "changed": false
}

thanks in advance for addressing this.

        andy


-- System Information:
Debian Release: 12.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-13-amd64 (SMP w/64 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, 
TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages ansible-core depends on:
ii  openssh-client        1:9.2p1-2+deb12u1
ii  python3               3.11.2-1+b1
ii  python3-cryptography  38.0.4-3
ii  python3-distutils     3.11.2-3
ii  python3-dnspython     2.3.0-1
ii  python3-httplib2      0.20.4-3
ii  python3-jinja2        3.1.2-1
ii  python3-netaddr       0.8.0-2
ii  python3-packaging     23.0-1
ii  python3-paramiko      2.12.0-2
ii  python3-pycryptodome  3.11.0+dfsg1-4
ii  python3-resolvelib    0.9.0-2
ii  python3-yaml          6.0-3+b2

Versions of packages ansible-core recommends:
ii  ansible              7.3.0+dfsg-1
pn  python3-argcomplete  <none>
pn  python3-jmespath     <none>
pn  python3-kerberos     <none>
pn  python3-libcloud     <none>
ii  python3-selinux      3.4-1+b6
pn  python3-winrm        <none>
pn  python3-xmltodict    <none>

Versions of packages ansible-core suggests:
pn  cowsay   <none>
pn  sshpass  <none>

-- no debconf information
>From 4b0d014d5840333457bd118c5fae5cf58325a877 Mon Sep 17 00:00:00 2001
From: Brian Coca <bc...@users.noreply.github.com>
Date: Mon, 8 May 2023 16:53:53 -0400
Subject: [PATCH] setup module, retry facter to handle --puppet errors (#80645)

* setup module, retry facter to handle --puppet errors

facter versions have changed how they deal with the --puppet flag
when puppet is not present, most versions will just ignore it and not error,
but initial versions of facter 4 changed the behaviour (later reverted).

fixes #80496
---
 changelogs/fragments/setup_facter_fix.yml     |  2 ++
 .../module_utils/facts/other/facter.py        | 23 +++++++------------
 2 files changed, 10 insertions(+), 15 deletions(-)
 create mode 100644 changelogs/fragments/setup_facter_fix.yml

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..063065251dd36e 100644
--- a/lib/ansible/module_utils/facts/other/facter.py
+++ b/lib/ansible/module_utils/facts/other/facter.py
@@ -1,17 +1,5 @@
-# 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
@@ -21,7 +9,6 @@
 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 +36,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):

Reply via email to