diff options
author | Christian Pointner <equinox@spreadspace.org> | 2019-04-13 23:31:30 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2019-04-14 00:07:27 +0200 |
commit | 3c55ccb22322f107c8b82a824e5e28a576af9ae0 (patch) | |
tree | ff5d57b3ff3684819ddcce4b0abb6d5d47024f1b /roles/cloud-install/filter_plugins/hroot.py | |
parent | add support for raspbian in prepare-dkms role (diff) |
added cloud install role/playbook
Diffstat (limited to 'roles/cloud-install/filter_plugins/hroot.py')
-rw-r--r-- | roles/cloud-install/filter_plugins/hroot.py | 33 |
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, + } |