Better error message

pull/10151/head
Toshio Kuratomi 10 years ago
parent f6e8ddfd5f
commit b3af2f9bee

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from ansible import errors from functools import partial
try: try:
import netaddr import netaddr
@ -27,6 +27,8 @@ else:
pass pass
mac_linux.word_fmt = '%.2x' mac_linux.word_fmt = '%.2x'
from ansible import errors
# ---- IP address and network query helpers ---- # ---- IP address and network query helpers ----
@ -595,8 +597,9 @@ def hwaddr(value, query = '', alias = 'hwaddr'):
def macaddr(value, query = ''): def macaddr(value, query = ''):
return hwaddr(value, query, alias = 'macaddr') return hwaddr(value, query, alias = 'macaddr')
def _need_netaddr(*args, **kwargs): def _need_netaddr(f_name, *args, **kwargs):
raise errors.AnsibleFilterError('python-netaddr package is not installed') raise errors.AnsibleFilterError('The {0} filter requires python-netaddr be'
' installed on the ansible controller'.format(f_name))
# ---- Ansible filters ---- # ---- Ansible filters ----
@ -620,4 +623,4 @@ class FilterModule(object):
return self.filter_map return self.filter_map
else: else:
# Need to install python-netaddr for these filters to work # 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)

Loading…
Cancel
Save