Repository: ansible-collections/community.general

Issue:
cobbler.py script not working - CentOS8.2 with python 3.6.8
_From @jeberhardt87 on Jul 09, 2020 10:47_

##### SUMMARY
The cobbler.py script from https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/cobbler.py is not working 
OS: CentOS 8.2
Python version: 3.6.8
Ansible version: 2.9.10


##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
cobbler.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```nsible 2.9.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Apr 16 2020, 01:36:27) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/home/ansible-user/ansible/hosts']
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
OS: CentOS 8.2
Python version: 3.6.8
Ansible version: 2.9.10

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
Download cobblery.py for testing from https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/cobbler.py
Copy it to /etc/ansible/cobbler.py and make it executable
Create /etc/ansible/cobbler.ini as described in https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html#inventory-script-example-cobbler
Modify host = in cobbler.ini
Run /etc/ansible/cobbler.py

##### EXPECTED RESULTS
Showing the output from cobbler.py


##### ACTUAL RESULTS
```
Traceback (most recent call last):
  File "/etc/ansible/cobbler.py", line 65, in <module>
    import xmlrpclib
ModuleNotFoundError: No module named 'xmlrpclib'


```


_Copied from original issue: ansible/ansible#70536_


Discussion:
I used python 2to3 and now the script is working.
Here is the output from diff (cobbler.py is the working file and cobbler.py.bak is the original file)

```
[ansible-user@ansible ansible-webapp]$ diff cobbler.py cobbler.py.bak 
65c65
< import xmlrpc.client
---
> import xmlrpclib
119c119
<             self.conn = xmlrpc.client.Server(self.cobbler_host, allow_none=True)
---
>             self.conn = xmlrpclib.Server(self.cobbler_host, allow_none=True)
```

and here is the working script:

[cobbler.py.txt](https://github.com/ansible-collections/community.general/files/4896944/cobbler.py.txt)

Greetings

Jürgen
cc @dagwieers
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/scripts/inventory/cobbler.py b/scripts/inventory/cobbler.py
--- a/scripts/inventory/cobbler.py
+++ b/scripts/inventory/cobbler.py
@@ -52,7 +52,10 @@
 import os
 import re
 from time import time
-import xmlrpclib
+try:  # Python 3
+    from xmlrpc.client import Server
+except ImportError:  # Python 2
+    from xmlrpclib import Server
 
 import json
 
@@ -106,7 +109,7 @@ def __init__(self):
 
     def _connect(self):
         if not self.conn:
-            self.conn = xmlrpclib.Server(self.cobbler_host, allow_none=True)
+            self.conn = Server(self.cobbler_host, allow_none=True)
             self.token = None
             if self.cobbler_username is not None:
                 self.token = self.conn.login(self.cobbler_username, self.cobbler_password)


Test patch: