From 535ce970679cf0b6e759e3f2bb110266769a896a Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 30 Sep 2013 12:55:13 -0500 Subject: [PATCH] Add fileglob Jinja2 filter. Fixes #3563 --- lib/ansible/runner/filter_plugins/core.py | 8 ++++++++ test/TestFilters.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/lib/ansible/runner/filter_plugins/core.py b/lib/ansible/runner/filter_plugins/core.py index 30b4e30b1a8..2729938dae7 100644 --- a/lib/ansible/runner/filter_plugins/core.py +++ b/lib/ansible/runner/filter_plugins/core.py @@ -21,6 +21,7 @@ import os.path import yaml import types import pipes +import glob from ansible import errors from ansible.utils import md5s @@ -74,6 +75,10 @@ def quote(a): ''' return its argument quoted for shell usage ''' return pipes.quote(a) +def fileglob(pathname): + ''' return list of matched files for glob ''' + return glob.glob(pathname) + class FilterModule(object): ''' Ansible core jinja2 filters ''' @@ -115,5 +120,8 @@ class FilterModule(object): # md5 hex digest of string 'md5': md5s, + + # file glob + 'fileglob': fileglob, } diff --git a/test/TestFilters.py b/test/TestFilters.py index 024185bce5d..ec92ac3f7fa 100644 --- a/test/TestFilters.py +++ b/test/TestFilters.py @@ -2,6 +2,7 @@ Test bundled filters ''' +import os.path import unittest, tempfile, shutil from ansible import playbook, inventory, callbacks import ansible.runner.filter_plugins.core @@ -83,6 +84,11 @@ class TestFilters(unittest.TestCase): a = ansible.runner.filter_plugins.core.quote('ls | wc -l') assert a == "'ls | wc -l'" + def test_fileglob(self): + pathname = os.path.join(os.path.dirname(__file__), '*') + a = ansible.runner.filter_plugins.core.fileglob(pathname) + assert __file__ in a + #def test_filters(self): # this test is pretty low level using a playbook, hence I am disabling it for now -- MPD.