knowledge/technology/tools/Ansible/lookups/ansible.builtin.env.md

26 lines
1.1 KiB
Markdown
Raw Normal View History

2023-12-04 10:02:23 +00:00
# ansible.builtin.env
Allows you to query the environment variables available on the controller when you invoked Ansible.
## Examples
```yml
- 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."
```