From b3af2f9beecc54e33c9b9eab7ac323d96ca3c68b Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 2 Feb 2015 08:45:15 -0800 Subject: [PATCH] Better error message --- lib/ansible/runner/filter_plugins/ipaddr.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/runner/filter_plugins/ipaddr.py b/lib/ansible/runner/filter_plugins/ipaddr.py index 285d2360589..bcb19b16fde 100644 --- a/lib/ansible/runner/filter_plugins/ipaddr.py +++ b/lib/ansible/runner/filter_plugins/ipaddr.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -from ansible import errors +from functools import partial try: import netaddr @@ -27,6 +27,8 @@ else: pass mac_linux.word_fmt = '%.2x' +from ansible import errors + # ---- IP address and network query helpers ---- @@ -595,8 +597,9 @@ def hwaddr(value, query = '', alias = 'hwaddr'): def macaddr(value, query = ''): return hwaddr(value, query, alias = 'macaddr') -def _need_netaddr(*args, **kwargs): - raise errors.AnsibleFilterError('python-netaddr package is not installed') +def _need_netaddr(f_name, *args, **kwargs): + raise errors.AnsibleFilterError('The {0} filter requires python-netaddr be' + ' installed on the ansible controller'.format(f_name)) # ---- Ansible filters ---- @@ -620,4 +623,4 @@ class FilterModule(object): return self.filter_map else: # Need to install python-netaddr for these filters to work - return dict((f, _need_netaddr) for f in self.filter_map) + return dict((f, partial(_need_netaddr, f)) for f in self.filter_map)