Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ To enable the YAML support with [pyyaml](http://pyyaml.org/):
pip install j2cli[yaml]
```

To enable [ansible filters](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters):

```
pip install j2cli[ansible]
```

Or both with

```
pip install j2cli[all]
```

## Tutorial

Suppose, you want to have an nginx configuration file template, `nginx.j2`:
Expand Down
14 changes: 14 additions & 0 deletions j2cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ def render_command(cwd, environ, stdin, argv):
renderer = Jinja2TemplateRenderer(cwd, args.undefined, j2_env_params=customize.j2_environment_params())
customize.j2_environment(renderer._env)

# Ansible filters - if available
try:
from ansible.plugins.filter import core as ansible_core_filters
from ansible.plugins.filter import urls as ansible_urls_filters
from ansible.plugins.filter import urlsplit as ansible_urlsplit_filters
from ansible.plugins.filter import mathstuff as ansible_mathstuff_filters

renderer.register_filters(ansible_core_filters.FilterModule().filters())
renderer.register_filters(ansible_urls_filters.FilterModule().filters())
renderer.register_filters(ansible_urlsplit_filters.FilterModule().filters())
renderer.register_filters(ansible_mathstuff_filters.FilterModule().filters())
except ImportError:
pass

# Filters, Tests
renderer.register_filters({
'docker_link': filters.docker_link,
Expand Down
12 changes: 12 additions & 0 deletions misc/_doc/README.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ To enable the YAML support with [pyyaml](http://pyyaml.org/):
pip install j2cli[yaml]
```

To enable [ansible filters](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters):

```
pip install j2cli[ansible]
```

Or both with

```
pip install j2cli[all]
```

## Tutorial

Suppose, you want to have an nginx configuration file template, `nginx.j2`:
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
'jinja2 >= 2.7.2',
],
extras_require={
'yaml': [pyyaml_version,]
'yaml': [pyyaml_version,],
'ansible': ['ansible >= 2.9.10',],
'all': [pyyaml_version, 'ansible >= 2.9.10',],
},
include_package_data=True,
zip_safe=False,
Expand Down