Variable defaults

Is there a way to default a variable inside of a tasks file? Use case is something like this… I have a list of tasks that I include in some play books, each of which I am currently defining the vars in. For a couple of those vars they’re there more for flexibility that actually necessity, and I am wondering if there is a way with jinja to maybe default them… something like {{varname|“def_value”}} or something that could be done in the task itself when that variable has not been defined.

Thanks for your help,
Stan

If you’re talking about roles, default variables should be put in the defaults/main.yml file.

​Almost there:

{{ varname | default('default_value') }}

Awesome, that’s exactly what I was in need of - thank you!