1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/lib/ansible/plugins/lookup/env.py
Elad Alfassa 1c157a8cf1 Fix env lookup plugin docs (#34235)
The env lookup plugin docs mistakenly mentioned dns TXT records,
and that it requires a DNS resolver library.
2017-12-26 05:20:33 -05:00

44 lines
1.2 KiB
Python

# (c) 2012, Jan-Piet Mens <jpmens(at)gmail.com>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = """
lookup: env
author: Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>
version_added: "0.9"
short_description: read the value of environment variables
description:
- Allows you to query the environment variables available on the controller when you invoked Ansible.
options:
_terms:
description: Environment variable or list of them to lookup the values for
required: True
"""
EXAMPLES = """
- debug: msg="{{ lookup('env','HOME') }} is an environment variable"
"""
RETURN = """
_list:
description:
- values from the environment variables.
type: list
"""
import os
from ansible.plugins.lookup import LookupBase
class LookupModule(LookupBase):
def run(self, terms, variables, **kwargs):
ret = []
for term in terms:
var = term.split()[0]
ret.append(os.getenv(var, ''))
return ret