aboutsummaryrefslogtreecommitdiff
path: root/foreman_ansible_inventory.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2016-10-03 11:42:30 +0200
committerDaniel Lobato García <me@daniellobato.me>2016-10-03 11:42:30 +0200
commitfaa364138450fc390906956e2db358387200e19d (patch)
treeb17fea637da13720fd3e679be464473732255aa0 /foreman_ansible_inventory.py
parentd66388b843f49ed556e003b746fcf41064c4171d (diff)
Python3 (#37)
* Handle python3's configparser as well * tests: Open file in text mode to avoid string bytes conversion with Python3 * tests: drop unnecessary dict These arent sortable in Python3 * Convert returned facts to list While Python2 has a list here Python3 returns dict_values which is not indexable as is. * tests: Parse url for comparison Python3 uses hash seeds for comparison so the QS parts dont have a fixed order. * Test python3.4 and python3.5 as well
Diffstat (limited to 'foreman_ansible_inventory.py')
-rwxr-xr-xforeman_ansible_inventory.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/foreman_ansible_inventory.py b/foreman_ansible_inventory.py
index a77ca5b..d969360 100755
--- a/foreman_ansible_inventory.py
+++ b/foreman_ansible_inventory.py
@@ -21,7 +21,6 @@
from __future__ import print_function
import argparse
-import ConfigParser
import copy
import os
import re
@@ -31,6 +30,12 @@ import sys
from time import time
try:
+ import ConfigParser
+except ImportError:
+ import configparser as ConfigParser
+
+
+try:
import json
except ImportError:
import simplejson as json
@@ -237,7 +242,7 @@ class ForemanInventory(object):
if len(ret.values()) == 0:
facts = {}
elif len(ret.values()) == 1:
- facts = ret.values()[0]
+ facts = list(ret.values())[0]
else:
raise ValueError("More than one set of facts returned for '%s'" % host)
return facts