summaryrefslogtreecommitdiff
path: root/lib/ansible/inventory
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2018-12-17 15:39:29 -0600
committerGitHub <noreply@github.com>2018-12-17 15:39:29 -0600
commita0d71e7735b611e97aa9f5ad464265b0e3e26ce6 (patch)
tree44b35b28c1fbc3376c1b5fe291f327cbd0284a72 /lib/ansible/inventory
parentba562043e11b0368e5651f4d50421d2a29b00c61 (diff)
downloadansible-a0d71e7735b611e97aa9f5ad464265b0e3e26ce6.tar.gz
Fix reverse_inventory order to work on python3 (#49895)
Diffstat (limited to 'lib/ansible/inventory')
-rw-r--r--lib/ansible/inventory/manager.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py
index 62d3e87b9a..de2041a68f 100644
--- a/lib/ansible/inventory/manager.py
+++ b/lib/ansible/inventory/manager.py
@@ -24,6 +24,9 @@ import os
import re
import itertools
+from operator import attrgetter
+from random import shuffle
+
from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
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)
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'))
elif order == 'reverse_inventory':
- hosts = sorted(self._hosts_patterns_cache[pattern_hash][:], reverse=True)
+ hosts = self._hosts_patterns_cache[pattern_hash][::-1]
else:
hosts = self._hosts_patterns_cache[pattern_hash][:]
if order == 'shuffle':
- from random import shuffle
shuffle(hosts)
elif order not in [None, 'inventory']:
raise AnsibleOptionsError("Invalid 'order' specified for inventory hosts: %s" % order)