diff --git a/ansible/library/config_facts.py b/ansible/library/config_facts.py index 13c2f0fee42..48256022a27 100644 --- a/ansible/library/config_facts.py +++ b/ansible/library/config_facts.py @@ -71,8 +71,16 @@ def create_maps(config): port_name_list = config["PORT"].keys() port_name_list_sorted = natsorted(port_name_list) - for idx, val in enumerate(port_name_list_sorted): - port_index_map[val] = idx + #get the port_index from config_db if available + port_index_map = { + name: int(v['index']) + for name, v in config['PORT'].iteritems() + if 'index' in v + } + if not port_index_map: + #if not available generate an index + for idx, val in enumerate(port_name_list_sorted): + port_index_map[val] = idx port_name_to_alias_map = { name : v['alias'] if 'alias' in v else '' for name, v in config["PORT"].iteritems()} @@ -136,7 +144,7 @@ def main(): cfg_file_path = PERSISTENT_CONFIG_PATH.format("") with open(cfg_file_path, "r") as f: config = json.load(f) - elif m_args["source"] == "running": + elif m_args["source"] == "running": config = get_running_config(module, namespace) results = get_facts(config) module.exit_json(ansible_facts=results)