Ansible Filter default

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

The filter provides a default value in case an undefined variable.

- name: Debug
  debug:
    msg: "value of {{ color | default('blue') }}"

In case a variable evaluates to false or to an empty string, and we want to provide a default value in this situation, default() filter needs a second parameter with the value true:

- name: Debug
  debug:
    msg: "{{ lookup('env', 'MY_USER') | default('admin', true) }}"

Also see: