---
- 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 'Undefined'
  ansible.builtin.debug:
    msg: "Hello {{ lookup('ansible.builtin.env', 'UNDEFINED_VARIABLE', default=Undefined) }}"

- 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()) }}"