|
|
@ -30,22 +30,21 @@ EXAMPLES = """
|
|
|
|
ansible.builtin.debug:
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "'{{ lookup('ansible.builtin.env', 'HOME') }}' is the HOME environment variable."
|
|
|
|
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.
|
|
|
|
- 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:
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ lookup('ansible.builtin.env', 'USR')|default('nobody', True) }} is the user."
|
|
|
|
msg: "Hello {{ lookup('ansible.builtin.env', 'UNDEFINED_VARIABLE') | default('World', True) }}"
|
|
|
|
|
|
|
|
|
|
|
|
- name: Example how to set default value if the variable is not defined, ignores USR=''
|
|
|
|
- name: Example how to set default value if the variable is not defined
|
|
|
|
ansible.builtin.debug:
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ lookup('ansible.builtin.env', 'USR', default='nobody') }} is the user."
|
|
|
|
msg: "Hello {{ lookup('ansible.builtin.env', 'UNDEFINED_VARIABLE', default='World') }}"
|
|
|
|
|
|
|
|
|
|
|
|
- name: Set default value to Undefined, if the variable is not defined
|
|
|
|
- name: Fail if the variable is not defined by setting default value to 'Undefined'
|
|
|
|
ansible.builtin.debug:
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ lookup('ansible.builtin.env', 'USR', default=Undefined) }} is the user."
|
|
|
|
msg: "Hello {{ lookup('ansible.builtin.env', 'UNDEFINED_VARIABLE', default=Undefined) }}"
|
|
|
|
|
|
|
|
|
|
|
|
- name: Set default value to undef(), if the variable is not defined
|
|
|
|
- name: Fail if the variable is not defined by setting default value to 'undef()'
|
|
|
|
ansible.builtin.debug:
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ lookup('ansible.builtin.env', 'USR', default=undef()) }} is the user."
|
|
|
|
msg: "Hello {{ lookup('ansible.builtin.env', 'UNDEFINED_VARIABLE', default=undef()) }}"
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
RETURN = """
|
|
|
|