https://github.com/simonkowallik/j2f5
j2cli extension with focus on templating F5 iRules
https://github.com/simonkowallik/j2f5
ansible f5-bigip f5networks irules j2cli templating
Last synced: 3 months ago
JSON representation
j2cli extension with focus on templating F5 iRules
- Host: GitHub
- URL: https://github.com/simonkowallik/j2f5
- Owner: simonkowallik
- Created: 2021-01-06T11:55:42.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-11-12T11:57:53.000Z (over 3 years ago)
- Last Synced: 2025-11-30T07:27:16.841Z (7 months ago)
- Topics: ansible, f5-bigip, f5networks, irules, j2cli, templating
- Language: Python
- Homepage: https://simonkowallik.github.io/j2f5/
- Size: 398 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# j2f5
[](https://github.com/simonkowallik/j2f5/actions/workflows/ci-pipeline.yaml)
`j2f5` is a customization for [j2cli](https://pypi.org/project/j2cli/), which again is a command line tool to template any kind of text based files using python's famous jinja2.
`j2f5` focuses on F5 related code (specifically iRules), but isn't limited to it. It is supposed to be a relatively lightweight addition to j2cli.
## Features
- adds ansible filters (when ansible is available)
- supports custom jinja2 delimiters
- sane formatting defaults
## by example:
Copy and run this example:
```shell
cat < configuration.yaml
# configuration.yaml
error:
heading: "Sorry :-("
message: "Sorry, we can't serve your request right now."
include_id: true
EOF
cat <<'EOF' > lb_sorry_page.irule.j2
# lb_sorry_page.irule.j2
when LB_FAILED {
{# generate unique error_id and log when error.include_id is true #}
{% if error.include_id %}
set error_id [lindex [AES::key 128] 2]
log local0.error "LB failed for [FLOW::this], error_id:$error_id"
{% endif %}
HTTP::respond 503 content "
{{error.heading}}
{{error.message}}
{% if error.include_id %}
error_id: $error_id
{% endif %}
" Connection Close
}
EOF
j2 --customize j2f5.py lb_sorry_page.irule.j2 configuration.yaml \
-o lb_sorry_page.irule
cat lb_sorry_page.irule
```
Will produce:
```tcl
# lb_sorry_page.irule.j2
when LB_FAILED {
set error_id [lindex [AES::key 128] 2]
log local0.error "LB failed for [FLOW::this], error_id:$error_id"
HTTP::respond 503 content "
Sorry :-(
Sorry, we can't serve your request right now.
error_id: $error_id
" Connection Close
}
```
In `configuration.yaml` set:
```yaml
include_id: false
```
Run:
```shell
j2 --customize j2f5.py lb_sorry_page.irule.j2 configuration.yaml \
-o lb_sorry_page.irule
cat lb_sorry_page.irule
```
And observe the result:
```tcl
# lb_sorry_page.irule.j2
when LB_FAILED {
HTTP::respond 503 content "
Sorry :-(
Sorry, we can't serve your request right now.
" Connection Close
}
```