DevOpsAddict
DevOpsAddict

Reputation: 61

Jinja2 and ansible/python : jinja2.exceptions.TemplateAssertionError: no filter named 'bool'

I try to translate this line

enabled: "{{ with_postgresql | default(false) | bool }}"

with jinja2 library code :

template = env.get_template(file)

But the result is KO and the error message is :

jinja2.exceptions.TemplateAssertionError: no filter named 'bool'

I need to import sometinhg else ?

Upvotes: 1

Views: 5442

Answers (1)

DevOpsAddict
DevOpsAddict

Reputation: 61

A solution is to add is line :

env.filters['bool']= bool

To the Jinja2 environment before calling the get_template

...
env = jinja2.Environment(loader=jinja2.FunctionLoader(spit_template))

env.filters['bool']= bool

output = env.get_template('name').render(with_postgresql = 'true')
...

I think bool is an ansible functionality.

Upvotes: 1

Related Questions