Repository: ansible-collections/community.general

Issue:
ovirt4.py fails withTypeError("option values must be strings") on fedora 32
<!--- Verify first that your issue is not already reported on GitHub -->
<!--- Also test if the latest release and devel branch are affected too -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
<!--- Explain the problem briefly below -->
System, Fedora 32
Python => Python 3.8.3

Running the sample dynamic inventory file for ovirt (ovirt4.py), ovir4.py fails with the following error:
```
Traceback (most recent call last):
File "./ovirt4.py", line 257, in
main()
File "./ovirt4.py", line 242, in main
connection = create_connection()
File "./ovirt4.py", line 119, in create_connection
config = configparser.SafeConfigParser(
File "/usr/lib64/python3.8/configparser.py", line 1228, in init
super().init(*args, **kwargs)
File "/usr/lib64/python3.8/configparser.py", line 639, in init
self._read_defaults(defaults)
File "/usr/lib64/python3.8/configparser.py", line 1219, in _read_defaults
self.read_dict({self.default_section: defaults})
File "/usr/lib64/python3.8/configparser.py", line 754, in read_dict
self.set(section, key, value)
File "/usr/lib64/python3.8/configparser.py", line 1200, in set
self._validate_value_types(option=option, value=value)
File "/usr/lib64/python3.8/configparser.py", line 1185, in _validate_value_types
raise TypeError("option values must be strings")
TypeError: option values must be strings
```
##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->

community.general/scripts/inventory/ovirt4.py

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
fedora 32
python => Python 3.8.3

##### Patch to fix error

```diff
brian@smeagol]$ diff -wruN ovirt4.py~ ovirt4.py
--- ovirt4.py~	2020-07-19 15:11:19.458776776 -0500
+++ ovirt4.py	2020-07-20 10:39:59.028799191 -0500
@@ -116,13 +116,13 @@
     config_path = os.environ.get('OVIRT_INI_PATH', default_path)
 
     # Create parser and add ovirt section if it doesn't exist:
-    config = configparser.SafeConfigParser(
+    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')
```


Discussion:
Files identified in the description:
* [`plugins/modules/cloud/misc/ovirt.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/cloud/misc/ovirt.py)
* [`plugins/modules/cloud/ovirt/ovirt_user_facts.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/cloud/ovirt/ovirt_user_facts.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
@brianmillett: Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:
- ansible version

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE/bug_report.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->
cc @machacekondra @vincentvdk
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
!component =scripts/inventory/ovirt4.py
Files identified in the description:
* [`scripts/inventory/ovirt4.py`](https://github.com/ansible-collections/community.general/blob/master/scripts/inventory/ovirt4.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Hi @brianmillett

thanks for spotting the issue, could you create a PR to fix that as you have a fix ?

Best.
Can confirm that this patch works, thanks @brianmillett !
-label needs_info
-label needs_template

Resolving patch:
diff --git a/scripts/inventory/ovirt4.py b/scripts/inventory/ovirt4.py
--- a/scripts/inventory/ovirt4.py
+++ b/scripts/inventory/ovirt4.py
@@ -56,6 +56,7 @@
 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)


Test patch: