Skip to content

CiliumBGPAdvertisement labels issue #13141

@codegenz

Description

@codegenz

Hi!
Issue while rendering a Kubernetes manifest template with Ansible/Jinja2 when labels is intended to be optional.
Render a CiliumBGPAdvertisement YAML where metadata.labels is included only if labels is provided in the input variable.

Error
During task execution Ansible fails with:
ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'labels'

Root cause
cilium_bgp_advertisement is defined, but it doesn’t always contain the labels key. In Jinja2, the expression in the if statement (cilium_bgp_advertisement.labels) is evaluated first, and it errors out before the condition can be checked.

Expected behavior
If labels is not provided, the template should render without metadata.labels and without failing.

Suggested fix / workaround
Use a defined-check or a safe getter, e.g.:

{% if cilium_bgp_advertisement.labels is defined %}
labels:
{{ cilium_bgp_advertisement.labels | to_nice_yaml(indent=2) | indent(2) }}
{% endif %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions