mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02: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:
parent
0f7e39fa1a
commit
87c37ea441
2 changed files with 22 additions and 8 deletions
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 collections import defaultdict
|
||||||
|
|
||||||
from ansible.module_utils.six.moves import configparser
|
from ansible.module_utils.six.moves import configparser
|
||||||
|
from ansible.module_utils.six import PY2
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
@ -106,14 +107,24 @@ def create_connection():
|
||||||
config_path = os.environ.get('OVIRT_INI_PATH', default_path)
|
config_path = os.environ.get('OVIRT_INI_PATH', default_path)
|
||||||
|
|
||||||
# Create parser and add ovirt section if it doesn't exist:
|
# Create parser and add ovirt section if it doesn't exist:
|
||||||
config = configparser.SafeConfigParser(
|
if PY2:
|
||||||
defaults={
|
config = configparser.SafeConfigParser(
|
||||||
'ovirt_url': os.environ.get('OVIRT_URL'),
|
defaults={
|
||||||
'ovirt_username': os.environ.get('OVIRT_USERNAME'),
|
'ovirt_url': os.environ.get('OVIRT_URL'),
|
||||||
'ovirt_password': os.environ.get('OVIRT_PASSWORD'),
|
'ovirt_username': os.environ.get('OVIRT_USERNAME'),
|
||||||
'ovirt_ca_file': os.environ.get('OVIRT_CAFILE', ''),
|
'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'):
|
if not config.has_section('ovirt'):
|
||||||
config.add_section('ovirt')
|
config.add_section('ovirt')
|
||||||
config.read(config_path)
|
config.read(config_path)
|
||||||
|
|
Loading…
Reference in a new issue