From bcfef8d0d442a0f1482810254f1914851963d08a Mon Sep 17 00:00:00 2001 From: Kevin Bell Date: Wed, 14 May 2014 23:08:51 -0700 Subject: [PATCH 1/2] Add a broken test that shows extensions not skipped --- test/units/TestInventory.py | 4 ++++ .../inventory_test_data/inventory_dir/4skip_extensions.ini | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 test/units/inventory_test_data/inventory_dir/4skip_extensions.ini diff --git a/test/units/TestInventory.py b/test/units/TestInventory.py index 4aae739a23..e8f85adbd4 100644 --- a/test/units/TestInventory.py +++ b/test/units/TestInventory.py @@ -439,3 +439,7 @@ class TestInventory(unittest.TestCase): actual_host_names = [host.name for host in group_greek] print "greek : %s " % actual_host_names assert actual_host_names == ['zeus', 'morpheus'] + + def test_dir_inventory_skip_extension(self): + inventory = self.dir_inventory() + assert 'skipme' not in [h.name for h in inventory.get_hosts()] diff --git a/test/units/inventory_test_data/inventory_dir/4skip_extensions.ini b/test/units/inventory_test_data/inventory_dir/4skip_extensions.ini new file mode 100644 index 0000000000..a30afe5fcc --- /dev/null +++ b/test/units/inventory_test_data/inventory_dir/4skip_extensions.ini @@ -0,0 +1,2 @@ +[skip] +skipme \ No newline at end of file From 92bd755b4736f5e73e1ce3b4cffd134722b0cb00 Mon Sep 17 00:00:00 2001 From: Kevin Bell Date: Wed, 14 May 2014 23:32:53 -0700 Subject: [PATCH 2/2] Fixed extension filtering in InventoryDirectory --- lib/ansible/inventory/dir.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ansible/inventory/dir.py b/lib/ansible/inventory/dir.py index 53a6349fc7..e3eda22695 100644 --- a/lib/ansible/inventory/dir.py +++ b/lib/ansible/inventory/dir.py @@ -36,13 +36,12 @@ class InventoryDirectory(object): self.parsers = [] self.hosts = {} self.groups = {} - + for i in self.names: # Skip files that end with certain extensions or characters - for ext in ("~", ".orig", ".bak", ".ini", ".retry", ".pyc", ".pyo"): - if i.endswith(ext): - continue + if any(i.endswith(ext) for ext in ("~", ".orig", ".bak", ".ini", ".retry", ".pyc", ".pyo")): + continue # Skip hidden files if i.startswith('.') and not i.startswith('./'): continue