/lib/ansible/runner/lookup_plugins/env.py

https://github.com/ajanthanm/ansible · Python · 41 lines · 18 code · 7 blank · 16 comment · 4 complexity · 19f65a59856baefd9b5fff5dec0ad70e MD5 · raw file

  1. # (c) 2012, Jan-Piet Mens <jpmens(at)gmail.com>
  2. #
  3. # This file is part of Ansible
  4. #
  5. # Ansible is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # Ansible is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
  17. from ansible import utils, errors
  18. from ansible.utils import template
  19. import os
  20. class LookupModule(object):
  21. def __init__(self, basedir=None, **kwargs):
  22. self.basedir = basedir
  23. def run(self, terms, inject=None, **kwargs):
  24. try:
  25. terms = template.template(self.basedir, terms, inject)
  26. except Exception, e:
  27. pass
  28. if isinstance(terms, basestring):
  29. terms = [ terms ]
  30. ret = []
  31. for term in terms:
  32. var = term.split()[0]
  33. ret.append(os.getenv(var, ''))
  34. return ret