mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-30 23:33:09 +00:00
* update configparser
* changelog
* handle multiple python version
* Update changelogs/fragments/2461-ovirt4-fix-configparser.yml
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update ovirt4.py
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 3100c32a00)
Co-authored-by: abikouo <79859644+abikouo@users.noreply.github.com>
This commit is contained in:
3
changelogs/fragments/2461-ovirt4-fix-configparser.yml
Normal file
3
changelogs/fragments/2461-ovirt4-fix-configparser.yml
Normal file
@@ -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).
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user