updated logict to better manage retrieving data from hostvars
diff --git a/library/cassandra_hosts.py b/library/cassandra_hosts.py index 62925d7..553afe5 100644 --- a/library/cassandra_hosts.py +++ b/library/cassandra_hosts.py
@@ -31,12 +31,23 @@ for cassandra_group_name in cassandra_groups: cassandra_ip_mappings[cassandra_group_name] = {} for ds_ip in cassandra_groups[cassandra_group_name]: - hostvar = hostvars[ds_ip] - try: - private_ip = hostvar[LOCAL_ADDRESS] - except KeyError as e: - hostvar[LOCAL_ADDRESS] = "{0}: {1}".format(NOT_DEFINED, e) - private_ip = hostvar[LOCAL_ADDRESS] + if ds_ip in hostvars: + hostvar = hostvars[ds_ip] + if LOCAL_ADDRESS in hostvar: + private_ip = hostvar[LOCAL_ADDRESS] + else: + private_ip = NOT_DEFINED + + # try: + # hostvar = hostvars[ds_ip] + # except KeyError as e: + # hostvar[ds_ip] = '{0}: {1}'.format(NOT_DEFINED, e) + + # try: + # private_ip = hostvar[LOCAL_ADDRESS] + # except KeyError as e: + # hostvar[LOCAL_ADDRESS] = "{0}: {1}".format(NOT_DEFINED, e) + # private_ip = hostvar[LOCAL_ADDRESS] cassandra_ip_map = cassandra_ip_mappings[cassandra_group_name] cassandra_ip_map[ds_ip] = { 'private_ip': private_ip }