summaryrefslogtreecommitdiff
path: root/roles/cloud/install/filter_plugins/hroot.py
diff options
context:
space:
mode:
Diffstat (limited to 'roles/cloud/install/filter_plugins/hroot.py')
-rw-r--r--roles/cloud/install/filter_plugins/hroot.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/roles/cloud/install/filter_plugins/hroot.py b/roles/cloud/install/filter_plugins/hroot.py
new file mode 100644
index 00000000..d2abff1b
--- /dev/null
+++ b/roles/cloud/install/filter_plugins/hroot.py
@@ -0,0 +1,33 @@
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+
+from ansible import errors
+
+
+def extract_ssh_key_fingerprints(data):
+ try:
+ return [k['key']['fingerprint'] for k in data]
+ except Exception as e:
+ raise errors.AnsibleFilterError("hroot_ssh_key_fingerprints(): %s" % str(e))
+
+
+def extract_serverip(data, server_name):
+ try:
+ ips = [s['server']['server_ip'] for s in data if s['server']['server_name'] == server_name]
+ if len(ips):
+ return ips[0]
+ raise errors.AnsibleFilterError("hroot_extract_serverip(): server %s not found" % server_name)
+ except Exception as e:
+ raise errors.AnsibleFilterError("hroot_extract_serverip(): %s" % str(e))
+
+
+class FilterModule(object):
+
+ ''' Ansible math jinja2 filters '''
+
+ def filters(self):
+ return {
+ 'hroot_extract_ssh_key_fingerprints': extract_ssh_key_fingerprints,
+ 'hroot_extract_serverip': extract_serverip,
+ }