summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelogs/fragments/split-host-pattern-empty-strings.yaml2
-rw-r--r--lib/ansible/inventory/manager.py2
-rw-r--r--test/integration/targets/inventory_limit/aliases1
-rw-r--r--test/integration/targets/inventory_limit/hosts.yml5
-rwxr-xr-xtest/integration/targets/inventory_limit/runme.sh31
-rw-r--r--test/units/plugins/inventory/test_inventory.py4
6 files changed, 44 insertions, 1 deletions
diff --git a/changelogs/fragments/split-host-pattern-empty-strings.yaml b/changelogs/fragments/split-host-pattern-empty-strings.yaml
new file mode 100644
index 0000000000..35af0f0e8b
--- /dev/null
+++ b/changelogs/fragments/split-host-pattern-empty-strings.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - account for empty strings in when splitting the host pattern (https://github.com/ansible/ansible/issues/61964)
diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py
index 14e61ba933..72ffa6c8d7 100644
--- a/lib/ansible/inventory/manager.py
+++ b/lib/ansible/inventory/manager.py
@@ -130,7 +130,7 @@ def split_host_pattern(pattern):
'''), pattern, re.X
)
- return [p.strip() for p in patterns]
+ return [p.strip() for p in patterns if p.strip()]
class InventoryManager(object):
diff --git a/test/integration/targets/inventory_limit/aliases b/test/integration/targets/inventory_limit/aliases
new file mode 100644
index 0000000000..3005e4b26d
--- /dev/null
+++ b/test/integration/targets/inventory_limit/aliases
@@ -0,0 +1 @@
+shippable/posix/group4
diff --git a/test/integration/targets/inventory_limit/hosts.yml b/test/integration/targets/inventory_limit/hosts.yml
new file mode 100644
index 0000000000..2e1b192730
--- /dev/null
+++ b/test/integration/targets/inventory_limit/hosts.yml
@@ -0,0 +1,5 @@
+all:
+ hosts:
+ host1:
+ host2:
+ host3:
diff --git a/test/integration/targets/inventory_limit/runme.sh b/test/integration/targets/inventory_limit/runme.sh
new file mode 100755
index 0000000000..6a142b3b1e
--- /dev/null
+++ b/test/integration/targets/inventory_limit/runme.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+set -eux
+
+trap 'echo "Host pattern limit test failed"' ERR
+
+# https://github.com/ansible/ansible/issues/61964
+
+# These tests should return all hosts
+ansible -i hosts.yml all --limit ,, --list-hosts | tee out ; grep -q 'hosts (3)' out
+ansible -i hosts.yml ,, --list-hosts | tee out ; grep -q 'hosts (3)' out
+ansible -i hosts.yml , --list-hosts | tee out ; grep -q 'hosts (3)' out
+ansible -i hosts.yml all --limit , --list-hosts | tee out ; grep -q 'hosts (3)' out
+ansible -i hosts.yml all --limit '' --list-hosts | tee out ; grep -q 'hosts (3)' out
+
+
+# Only one host
+ansible -i hosts.yml all --limit ,,host1 --list-hosts | tee out ; grep -q 'hosts (1)' out
+ansible -i hosts.yml ,,host1 --list-hosts | tee out ; grep -q 'hosts (1)' out
+
+ansible -i hosts.yml all --limit host1,, --list-hosts | tee out ; grep -q 'hosts (1)' out
+ansible -i hosts.yml host1,, --list-hosts | tee out ; grep -q 'hosts (1)' out
+
+
+# Only two hosts
+ansible -i hosts.yml all --limit host1,,host3 --list-hosts | tee out ; grep -q 'hosts (2)' out
+ansible -i hosts.yml host1,,host3 --list-hosts | tee out ; grep -q 'hosts (2)' out
+
+ansible -i hosts.yml all --limit 'host1, , ,host3' --list-hosts | tee out ; grep -q 'hosts (2)' out
+ansible -i hosts.yml 'host1, , ,host3' --list-hosts | tee out ; grep -q 'hosts (2)' out
+
diff --git a/test/units/plugins/inventory/test_inventory.py b/test/units/plugins/inventory/test_inventory.py
index 48c3f9834a..66b5ec3787 100644
--- a/test/units/plugins/inventory/test_inventory.py
+++ b/test/units/plugins/inventory/test_inventory.py
@@ -49,6 +49,10 @@ class TestInventory(unittest.TestCase):
'a:b': ['a', 'b'],
' a : b ': ['a', 'b'],
'foo:bar:baz[1:2]': ['foo', 'bar', 'baz[1:2]'],
+ 'a,,b': ['a', 'b'],
+ 'a, ,b,,c, ,': ['a', 'b', 'c'],
+ ',': [],
+ '': [],
}
pattern_lists = [