From fd02443d4235cd632f33e1d77e005ae463b9c444 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Thu, 20 Jun 2013 07:55:35 +0200 Subject: [PATCH] Enable negated patterns A host pattern of the form '!foo' by itself does not work, but 'all:!foo' does. If the first pattern is a negation, this commit automatically prepends 'all'. Signed-off-by: martin f. krafft --- lib/ansible/inventory/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index d5df2f89d9..f85add0ad7 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -136,6 +136,11 @@ class Inventory(object): finds hosts that match a list of patterns. Handles negative matches as well as intersection matches. """ + try: + if patterns[0].startswith("!"): + patterns.insert(0, "all") + except IndexError: + pass hosts = set() for p in patterns: