An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# j2f5

[![CI Pipeline](https://github.com/simonkowallik/j2f5/actions/workflows/ci-pipeline.yaml/badge.svg)](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
}
```