Last active
March 31, 2016 07:13
-
-
Save dochang/0f67e3a97aaef40fcd3781142af2e4eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (c) 2016, ZHANG Weiyi <[email protected]> | |
# | |
# This file is NOT part of Ansible | |
from __future__ import (absolute_import, division, print_function) | |
__metaclass_ = type | |
import subprocess | |
from ansible.errors import AnsibleError | |
from ansible.plugins.lookup import LookupBase | |
class LookupModule(LookupBase): | |
def run(self, terms, variables, **kwargs): | |
ret = [] | |
for term in terms: | |
''' | |
http://docs.python.org/2/library/subprocess.html#popen-constructor | |
The shell argument (which defaults to False) specifies whether to use the | |
shell as the program to execute. If shell is True, it is recommended to pass | |
args as a string rather than as a sequence | |
https://github.com/ansible/ansible/issues/6550 | |
''' | |
term = str(term) | |
p = subprocess.Popen("pass show " + term, cwd=self._loader.get_basedir(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
(stdout, stderr) = p.communicate() | |
if p.returncode == 0: | |
ret.append(stdout.decode("utf-8").rstrip()) | |
else: | |
raise AnsibleError("lookup_plugin.pass(%s) returned %d: %s" % (term, p.returncode, stderr.decode("utf-8"))) | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment