From 695e456cb045a875dd641283dad5d2d26b435264 Mon Sep 17 00:00:00 2001 From: Scott Cunningham Date: Wed, 29 Jul 2015 10:46:40 +0100 Subject: [PATCH] add credstash lookup plugin --- lib/ansible/plugins/lookup/credstash.py | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/ansible/plugins/lookup/credstash.py diff --git a/lib/ansible/plugins/lookup/credstash.py b/lib/ansible/plugins/lookup/credstash.py new file mode 100644 index 0000000000..1e9f3ef722 --- /dev/null +++ b/lib/ansible/plugins/lookup/credstash.py @@ -0,0 +1,42 @@ +# (c) 2015, Ensighten +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.errors import AnsibleError +from ansible.plugins.lookup import LookupBase + +import credstash + + +class LookupModule(LookupBase): + def run(self, terms, variables, **kwargs): + + if isinstance(terms, basestring): + terms = [terms] + + ret = [] + for term in terms: + try: + val = credstash.getSecret(term, **kwargs) + except credstash.ItemNotFound: + raise AnsibleError('Key {} not found'.format(term)) + except Exception as e: + raise AnsibleError('Encountered exception while fetching {}: {}'.format(term, e.message)) + ret.append(val) + + return ret