Skip to content

Support for specifying which Undefined Type to use - #146

Open
ohardeng wants to merge 1 commit into
mattrobenolt:mainfrom
ohardeng:main
Open

Support for specifying which Undefined Type to use#146
ohardeng wants to merge 1 commit into
mattrobenolt:mainfrom
ohardeng:main

Conversation

@ohardeng

@ohardeng ohardeng commented Jun 2, 2026

Copy link
Copy Markdown

Currently only the default Undefined and StrictUndefined are supported, but I needed ChainableUndefined in my usecase for parsing deployment templates normally run with ansible.

This PR adds the --undefined option to allow you to select which behaviour you want for your undefineds.

Minimal example:

test_template.yml

---
apiVersion: test
spec:
  env:
    - name: ENVIRONMENT_OPENTELEMETRY_SDK_DISABLED
      value: "{{ opentelemetry.sdk.disabled | default(true) }}"
    - name: ENVIRONMENT_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT
      value: "{{ opentelemetry.exporter.otlp.endpoint | default('') }}"
    - name: APP_NAME
      value: "{{ app_name }}"

test_vars.yml

app_name: test-app

Currently this fails

jinja2 test_template.yml test_vars.yml
UndefinedError: 'opentelemetry' is undefined

With this PR it succeds

python3 -m jinja2cli test_template.yml test_vars.yml -f yaml --undefined=ChainableUndefined
---
apiVersion: test
spec:
  env:
    - name: ENVIRONMENT_OPENTELEMETRY_SDK_DISABLED
      value: "True"
    - name: ENVIRONMENT_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT
      value: ""
    - name: APP_NAME
      value: "test-app"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant