env¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version0.9.
Synopsis¶
- Allows you to query the environment variables available on the controller when you invoked Ansible.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _terms required |
Environment variable or list of them to lookup the values for. | |
| default raw |
What return when the variable is undefined Version Added: 2.13 |
Notes¶
Note
- You can pass the C(Undefined) object as O(default) to force an undefined error
Examples¶
- 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
ansible.builtin.debug:
msg: "Hello {{ lookup('ansible.builtin.env', 'UNDEFINED_VARIABLE') | default('World', True) }}"
- name: Example how to set default value if the variable is not defined
ansible.builtin.debug:
msg: "Hello {{ lookup('ansible.builtin.env', 'UNDEFINED_VARIABLE', default='World') }}"
- name: Fail if the variable is not defined by setting default value to 'undef()'
ansible.builtin.debug:
msg: "Hello {{ lookup('ansible.builtin.env', 'UNDEFINED_VARIABLE', default=undef()) }}"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _list | list | Values from the environment variables. |
Authors¶
- Jan-Piet Mens (@jpmens)