From d362a190f2877b39ee01f48f1513f1615322abc4 Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Fri, 3 May 2019 13:46:14 +0300 Subject: [PATCH] Fix Ansible: [WARNING]: Found both group and host with same name Avoid setting group and host with the same name --- requirements.txt | 2 +- src/ops/inventory/ec2inventory.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 35f2e315..5894a6c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ PyYAML==3.13 azure-common==1.1.4 azure==2.0.0rc5 msrestazure==0.4.6 -jinja2<2.9 +Jinja2==2.10.1 hashmerge python-consul hvac>=0.5.0 diff --git a/src/ops/inventory/ec2inventory.py b/src/ops/inventory/ec2inventory.py index a8aeb48c..a2963682 100644 --- a/src/ops/inventory/ec2inventory.py +++ b/src/ops/inventory/ec2inventory.py @@ -242,12 +242,16 @@ def get_host_info(self): def push(self, my_dict, key, element): ''' Push an element onto an array that may not have been defined in the dict ''' + if key == element: + return group_info = my_dict.setdefault(key, []) if isinstance(group_info, dict): host_list = group_info.setdefault('hosts', []) - host_list.append(element) + if element not in host_list: + host_list.append(element) else: - group_info.append(element) + if element not in group_info: + group_info.append(element) def push_group(self, my_dict, key, element): ''' Push a group as a child of another group. '''