From 23b9a389096148502113a502066da1b604ef0981 Mon Sep 17 00:00:00 2001 From: Edoardo Putti Date: Wed, 28 Jun 2017 18:29:37 +0200 Subject: [PATCH] draft for filter to get ip from hostname --- filter_plugin/ip_from_inventory.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 filter_plugin/ip_from_inventory.py diff --git a/filter_plugin/ip_from_inventory.py b/filter_plugin/ip_from_inventory.py new file mode 100644 index 0000000..f19551a --- /dev/null +++ b/filter_plugin/ip_from_inventory.py @@ -0,0 +1,15 @@ +from ansible.hostvars import HostVars + +def ip_from_inventory(hostname): + """ + replace this ``{{ hostvars[hostname]['ansible_host'] }}`` + with something nicer such as `` {{ hostname | ip_from_inventory }}`` + """ + return HostVars[hostname]['ansible_host'] + +class FilterModule(object): + def filter(self): + return { + 'ip_from_inventory': ip_from_inventory, + } +