1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes #5196 return a unique list of hostnames for a single host pattern

This commit is contained in:
James Tanner 2014-01-06 14:19:20 -05:00
parent ccbc99fe4f
commit ab51bd23a2

View file

@ -21,6 +21,7 @@ import fnmatch
import os
import re
import subprocess
from sets import Set
import ansible.constants as C
from ansible.inventory.ini import InventoryParser
@ -251,6 +252,8 @@ class Inventory(object):
""" Get all host names matching the pattern """
hosts = []
hostnames = Set()
# ignore any negative checks here, this is handled elsewhere
pattern = pattern.replace("!","").replace("&", "")
@ -259,8 +262,9 @@ class Inventory(object):
for group in groups:
for host in group.get_hosts():
if pattern == 'all' or self._match(group.name, pattern) or self._match(host.name, pattern):
if host not in results:
if host not in results and host.name not in hostnames:
results.append(host)
hostnames.add(host.name)
return results
def clear_pattern_cache(self):