From 87c37ea44107ce9969680a298cdc77899cce58a0 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 22 May 2021 14:36:44 +0200 Subject: [PATCH] ovir4 inventory script (#2461) (#2582) * update configparser * changelog * handle multiple python version * Update changelogs/fragments/2461-ovirt4-fix-configparser.yml Co-authored-by: Felix Fontein * Update ovirt4.py Co-authored-by: Felix Fontein (cherry picked from commit 3100c32a00d6a350274884aba06afe51a71d5253) Co-authored-by: abikouo <79859644+abikouo@users.noreply.github.com> --- .../2461-ovirt4-fix-configparser.yml | 3 +++ scripts/inventory/ovirt4.py | 27 +++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/2461-ovirt4-fix-configparser.yml diff --git a/changelogs/fragments/2461-ovirt4-fix-configparser.yml b/changelogs/fragments/2461-ovirt4-fix-configparser.yml new file mode 100644 index 0000000000..6e3845b21a --- /dev/null +++ b/changelogs/fragments/2461-ovirt4-fix-configparser.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - ovir4 inventory script - improve configparser creation to avoid crashes for options without values (https://github.com/ansible-collections/community.general/issues/674). diff --git a/scripts/inventory/ovirt4.py b/scripts/inventory/ovirt4.py index afff18dbdb..84b68a1258 100755 --- a/scripts/inventory/ovirt4.py +++ b/scripts/inventory/ovirt4.py @@ -56,6 +56,7 @@ import sys from collections import defaultdict from ansible.module_utils.six.moves import configparser +from ansible.module_utils.six import PY2 import json @@ -106,14 +107,24 @@ def create_connection(): config_path = os.environ.get('OVIRT_INI_PATH', default_path) # Create parser and add ovirt section if it doesn't exist: - config = configparser.SafeConfigParser( - defaults={ - 'ovirt_url': os.environ.get('OVIRT_URL'), - 'ovirt_username': os.environ.get('OVIRT_USERNAME'), - 'ovirt_password': os.environ.get('OVIRT_PASSWORD'), - 'ovirt_ca_file': os.environ.get('OVIRT_CAFILE', ''), - } - ) + if PY2: + config = configparser.SafeConfigParser( + defaults={ + 'ovirt_url': os.environ.get('OVIRT_URL'), + 'ovirt_username': os.environ.get('OVIRT_USERNAME'), + 'ovirt_password': os.environ.get('OVIRT_PASSWORD'), + 'ovirt_ca_file': os.environ.get('OVIRT_CAFILE', ''), + }, allow_no_value=True + ) + else: + config = configparser.ConfigParser( + defaults={ + 'ovirt_url': os.environ.get('OVIRT_URL'), + 'ovirt_username': os.environ.get('OVIRT_USERNAME'), + 'ovirt_password': os.environ.get('OVIRT_PASSWORD'), + 'ovirt_ca_file': os.environ.get('OVIRT_CAFILE', ''), + }, allow_no_value=True + ) if not config.has_section('ovirt'): config.add_section('ovirt') config.read(config_path)