diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2023-05-08 16:53:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 16:53:53 -0400 |
commit | 4b0d014d5840333457bd118c5fae5cf58325a877 (patch) | |
tree | 8ed74ded1c41368f97e0b362c927db01e4da322b | |
parent | 790e0b09836e828af3c2d19ea3351e288d019b36 (diff) | |
download | ansible-4b0d014d5840333457bd118c5fae5cf58325a877.tar.gz |
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
-rw-r--r-- | changelogs/fragments/setup_facter_fix.yml | 2 | ||||
-rw-r--r-- | lib/ansible/module_utils/facts/other/facter.py | 23 |
2 files changed, 10 insertions, 15 deletions
diff --git a/changelogs/fragments/setup_facter_fix.yml b/changelogs/fragments/setup_facter_fix.yml new file mode 100644 index 0000000000..78a6b005a4 --- /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 3f83999d41..063065251d 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 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 +36,12 @@ class FacterFactCollector(BaseFactCollector): # 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): |