ansible / ansible.builtin / v2.16.5 / lookup / env Read the value of environment variables | "added in version" 0.9 of ansible.builtin" Authors: Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>ansible.builtin.env (v2.16.5) — lookup
pip
Install with pip install ansible-core==2.16.5
Allows you to query the environment variables available on the controller when you invoked Ansible.
- name: Basic usage ansible.builtin.debug: msg: "'{{ lookup('ansible.builtin.env', 'HOME') }}' is the HOME environment variable."
- name: Before 2.13, how to set default value if the variable is not defined. This cannot distinguish between USR undefined and USR=''. ansible.builtin.debug: msg: "{{ lookup('ansible.builtin.env', 'USR')|default('nobody', True) }} is the user."
- name: Example how to set default value if the variable is not defined, ignores USR='' ansible.builtin.debug: msg: "{{ lookup('ansible.builtin.env', 'USR', default='nobody') }} is the user."
- name: Set default value to Undefined, if the variable is not defined ansible.builtin.debug: msg: "{{ lookup('ansible.builtin.env', 'USR', default=Undefined) }} is the user."
- name: Set default value to undef(), if the variable is not defined ansible.builtin.debug: msg: "{{ lookup('ansible.builtin.env', 'USR', default=undef()) }} is the user."
_terms: description: - Environment variable or list of them to lookup the values for. required: true default: default: '' description: What return when the variable is undefined type: raw version_added: '2.13' version_added_collection: ansible.builtin
_list: description: - Values from the environment variables. type: list