mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ovir4 inventory script (#2461)
* 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>
This commit is contained in:
parent
8f083d5d85
commit
3100c32a00
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 ansible.module_utils.six.moves import configparser
|
||||
from ansible.module_utils.six import PY2
|
||||
|
||||
import json
|
||||
|
||||
|
@ -106,13 +107,23 @@ def create_connection():
|
|||
config_path = os.environ.get('OVIRT_INI_PATH', default_path)
|
||||
|
||||
# Create parser and add ovirt section if it doesn't exist:
|
||||
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')
|
||||
|
|
Loading…
Reference in a new issue