summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorThomas Stringer <github@trstringer.com>2017-10-05 14:49:35 -0400
committerToshio Kuratomi <a.badger@gmail.com>2017-10-05 11:50:10 -0700
commit827d7e7cc609c3aef0f180d7496d1584aaa77e90 (patch)
tree57edd4c9d91684ba69d3bd266901a72590d2d86a /contrib
parent9bcb6f437258d8b2477e6ca2714d1af97b44fe34 (diff)
downloadansible-827d7e7cc609c3aef0f180d7496d1584aaa77e90.tar.gz
refactor azure dynamic inventory script configparser import to support python3 (#31370)
* refactor configparser import to support python3 * change ModuleNotFoundError to ImportError (cherry picked from commit cb01f33d1e3c99399c19b2e3a7a3391be7bb698c)
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/inventory/azure_rm.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/contrib/inventory/azure_rm.py b/contrib/inventory/azure_rm.py
index b3b7e1e904..6c79d8b9a2 100755
--- a/contrib/inventory/azure_rm.py
+++ b/contrib/inventory/azure_rm.py
@@ -187,14 +187,18 @@ Version: 1.0.0
'''
import argparse
-import ConfigParser
import json
import os
import re
import sys
import inspect
-import traceback
+try:
+ # python2
+ import ConfigParser as cp
+except ImportError:
+ # python3
+ import configparser as cp
from packaging.version import Version
@@ -326,7 +330,7 @@ class AzureRM(object):
path = expanduser("~")
path += "/.azure/credentials"
try:
- config = ConfigParser.ConfigParser()
+ config = cp.ConfigParser()
config.read(path)
except Exception as exc:
self.fail("Failed to access {0}. Check that the file exists and you have read "
@@ -795,7 +799,7 @@ class AzureInventory(object):
config = None
settings = None
try:
- config = ConfigParser.ConfigParser()
+ config = cp.ConfigParser()
config.read(path)
except:
pass