From 7eca6ef9509ae112a5384dfbf233ec9bd8713b9d Mon Sep 17 00:00:00 2001 From: Edoardo Putti Date: Sun, 27 Aug 2017 16:57:03 +0200 Subject: [PATCH] use check instead of try, except block in filter ip_from_address --- filter_plugins/ip_from_inventory.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/filter_plugins/ip_from_inventory.py b/filter_plugins/ip_from_inventory.py index 3cde075..992c24e 100644 --- a/filter_plugins/ip_from_inventory.py +++ b/filter_plugins/ip_from_inventory.py @@ -5,10 +5,10 @@ def ip_from_inventory(hostvars, hostname): replace this ``{{ hostvars[hostname]['ansible_host'] }}`` with something nicer such as `` {{ hostvars | ip_from_inventory(hostname) }}`` """ - try: - return hostvars[hostname]['ansible_host'] - except KeyError: - raise AnsibleError('hostname "{hostname}" not found in inventory'.format(hostname=hostname)) + if not hostname in hostvars: + raise AnsibleError(' hostname "{hostname}" not found in inventory'.format(hostname=hostname)) + + return hostvars[hostname]['ansible_host'] class FilterModule(object): def filters(self):