diff --git a/contrib/inventory/rax.py b/contrib/inventory/rax.py index ce294145537..4ef2e130d7a 100755 --- a/contrib/inventory/rax.py +++ b/contrib/inventory/rax.py @@ -155,8 +155,6 @@ import ConfigParser from six import iteritems -from ansible.constants import get_config, mk_boolean - try: import json except ImportError: @@ -170,6 +168,8 @@ except ImportError: from time import time +from ansible.constants import get_config, mk_boolean + NON_CALLABLES = (basestring, bool, dict, int, list, type(None)) @@ -226,12 +226,21 @@ def _list_into_cache(regions): prefix = get_config(p, 'rax', 'meta_prefix', 'RAX_META_PREFIX', 'meta') - networks = get_config(p, 'rax', 'access_network', 'RAX_ACCESS_NETWORK', - 'public', islist=True) try: - ip_versions = map(int, get_config(p, 'rax', 'access_ip_version', - 'RAX_ACCESS_IP_VERSION', 4, - islist=True)) + # Ansible 2.3+ + networks = get_config(p, 'rax', 'access_network', + 'RAX_ACCESS_NETWORK', 'public', value_type='list') + except TypeError: + # Ansible 2.2.x and below + networks = get_config(p, 'rax', 'access_network', + 'RAX_ACCESS_NETWORK', 'public', islist=True) + try: + try: + ip_versions = map(int, get_config(p, 'rax', 'access_ip_version', + 'RAX_ACCESS_IP_VERSION', 4, value_type='list')) + except TypeError: + ip_versions = map(int, get_config(p, 'rax', 'access_ip_version', + 'RAX_ACCESS_IP_VERSION', 4, islist=True)) except: ip_versions = [4] else: @@ -422,8 +431,15 @@ def setup(): if region: regions.append(region) else: - region_list = get_config(p, 'rax', 'regions', 'RAX_REGION', 'all', - islist=True) + try: + # Ansible 2.3+ + region_list = get_config(p, 'rax', 'regions', 'RAX_REGION', 'all', + value_type='list') + except TypeError: + # Ansible 2.2.x and below + region_list = get_config(p, 'rax', 'regions', 'RAX_REGION', 'all', + islist=True) + for region in region_list: region = region.strip().upper() if region == 'ALL':