|
|
@ -24,6 +24,9 @@ import os
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import itertools
|
|
|
|
import itertools
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from operator import attrgetter
|
|
|
|
|
|
|
|
from random import shuffle
|
|
|
|
|
|
|
|
|
|
|
|
from ansible import constants as C
|
|
|
|
from ansible import constants as C
|
|
|
|
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
|
|
|
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
|
|
|
from ansible.inventory.data import InventoryData
|
|
|
|
from ansible.inventory.data import InventoryData
|
|
|
@ -367,14 +370,12 @@ class InventoryManager(object):
|
|
|
|
|
|
|
|
|
|
|
|
# sort hosts list if needed (should only happen when called from strategy)
|
|
|
|
# sort hosts list if needed (should only happen when called from strategy)
|
|
|
|
if order in ['sorted', 'reverse_sorted']:
|
|
|
|
if order in ['sorted', 'reverse_sorted']:
|
|
|
|
from operator import attrgetter
|
|
|
|
|
|
|
|
hosts = sorted(self._hosts_patterns_cache[pattern_hash][:], key=attrgetter('name'), reverse=(order == 'reverse_sorted'))
|
|
|
|
hosts = sorted(self._hosts_patterns_cache[pattern_hash][:], key=attrgetter('name'), reverse=(order == 'reverse_sorted'))
|
|
|
|
elif order == 'reverse_inventory':
|
|
|
|
elif order == 'reverse_inventory':
|
|
|
|
hosts = sorted(self._hosts_patterns_cache[pattern_hash][:], reverse=True)
|
|
|
|
hosts = self._hosts_patterns_cache[pattern_hash][::-1]
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
hosts = self._hosts_patterns_cache[pattern_hash][:]
|
|
|
|
hosts = self._hosts_patterns_cache[pattern_hash][:]
|
|
|
|
if order == 'shuffle':
|
|
|
|
if order == 'shuffle':
|
|
|
|
from random import shuffle
|
|
|
|
|
|
|
|
shuffle(hosts)
|
|
|
|
shuffle(hosts)
|
|
|
|
elif order not in [None, 'inventory']:
|
|
|
|
elif order not in [None, 'inventory']:
|
|
|
|
raise AnsibleOptionsError("Invalid 'order' specified for inventory hosts: %s" % order)
|
|
|
|
raise AnsibleOptionsError("Invalid 'order' specified for inventory hosts: %s" % order)
|
|
|
|