Complex computation within jinja-templates in roles?

52 views
Skip to first unread message

Hartmut Goebel

unread,
Jan 5, 2015, 9:42:23 AM1/5/15
to ansible...@googlegroups.com
Hi,

I'm seeking a way to have complex computation within jinja-templates in
roles. The computations I need are approx 100 lines of code, so using
the jinja2-syntx "{%....%} for each line is tremulous.

My first idea was to implement a python filter-plugin. But Ansible does
not search for plugins within the role's directory.

* Is there a way to include a block of Python-code into the template?

* Is there a way to directly call a Python-script or function located
relativly to the template?

* Any other solutions?

--
Regards
Hartmut Goebel

| Hartmut Goebel | h.go...@crazy-compilers.com |
| www.crazy-compilers.com | compilers which you thought are impossible |

Tomasz Kontusz

unread,
Jan 5, 2015, 10:05:45 AM1/5/15
to ansible...@googlegroups.com


Hartmut Goebel <h.go...@crazy-compilers.com> napisał:
>Hi,
>
>I'm seeking a way to have complex computation within jinja-templates in
>roles. The computations I need are approx 100 lines of code, so using
>the jinja2-syntx "{%....%} for each line is tremulous.
>
>My first idea was to implement a python filter-plugin. But Ansible does
>not search for plugins within the role's directory.
>
>* Is there a way to include a block of Python-code into the template?

No

>* Is there a way to directly call a Python-script or function located
>relativly to the template?
You can try using `first_found` lookup to locate it, and `lines` lookup to call it.

>* Any other solutions?
You can also implement that computation as a custom module, and call it before calling template
--
Wysłane za pomocą K-9 Mail.

Brian Coca

unread,
Jan 5, 2015, 11:08:57 AM1/5/15
to ansible...@googlegroups.com
a filter_plugins (at play or role level) directory should enable you
to load custom plugins.


--
Brian Coca

Hartmut Goebel

unread,
Jan 5, 2015, 11:35:27 AM1/5/15
to ansible...@googlegroups.com
Am 05.01.2015 um 16:05 schrieb Tomasz Kontusz:
>> >* Is there a way to directly call a Python-script or function located
>> >relativly to the template?
> You can try using `first_found` lookup to locate it, and `lines` lookup to call it.

I'll try this.

>> >* Any other solutions?
> You can also implement that computation as a custom module, and call it before calling template

For me this sound wrong, because the module will be carried out on the
remote node, while there is nothing to do – except computing some
already known data.

Tomasz Kontusz

unread,
Jan 5, 2015, 11:38:44 AM1/5/15
to ansible...@googlegroups.com
On 05.01.2015 17:35, Hartmut Goebel wrote:
>>>> * Any other solutions?
>> You can also implement that computation as a custom module, and call it before calling template
> For me this sound wrong, because the module will be carried out on the
> remote node, while there is nothing to do – except computing some
> already known data.
You can always call it with local_action, then it won't be transferred
to the remote host.
Reply all
Reply to author
Forward
0 new messages