Unclear templating error started from 2.19.0

Going to migrate from ansible-core 2.18 to 2.20 for 3pp lifecycle management, and it was actually delayed due to changes in 2.19, and I am still stuck with that.

So, simple playbook (written for test):

---
- name: Test play
  hosts: active
  tasks:

    - name: Get secret with k8s_info
      kubernetes.core.k8s_info:
        kind: Secret
        name: secretname
        namespace: "{{ namespace }}"
        kubeconfig: "~/.kube/config"
      register: mysecret
      ignore_errors: true

Simple inventory:

all:
  children:
    active_group:
      hosts:
        active:
          ansible_connection: local
          namespace: test-namespace

Versions:

root@6e49f0e3df11:/# ansible --version
ansible [core 2.20.0]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.13/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.13.7 (main, Aug 15 2025, 22:13:08) [GCC 14.2.0] (/usr/local/bin/python3.13)
  jinja version = 3.1.6
  pyyaml version = 6.0.3 (with libyaml v0.2.5)
root@6e49f0e3df11:/# ansible-lint --version
ansible-lint 25.11.0 using ansible-core:2.20.0 ansible-compat:25.11.0 ruamel-yaml:0.18.16 ruamel-yaml-clib:0.2.15
root@6e49f0e3df11:/# ansible-galaxy collection list

# /root/.ansible/collections/ansible_collections
Collection      Version
--------------- -------
kubernetes.core 6.2.0
root@6e49f0e3df11:/#

It’s look completely fine, hovewer I got lint error:

jinja[invalid]: Error rendering template: Type 'type' is unsupported for variable storage.
opt/test.yml:13:20 Task/Handler: Get secret with k8s_info

Read documentation for instructions on how to ignore specific rule violations.

# Rule Violation Summary

  1 jinja profile:basic tags:formatting

Failed: 1 failure(s), 0 warning(s) in 2 files processed of 3 encountered. The last profile that met the validation criteria was 'min'.

It worked completely fine for 2.18 and earlier, and I’m struggling with understanding what is wrong here. Any suggestions?

Ok, as the WA changed to

---
- name: Test play
  hosts: active
  tasks:

    - name: Get secret with k8s_info
      kubernetes.core.k8s_info:
        kind: Secret
        name: secretname
        namespace: "{{ namespace | to_string }}"
        kubeconfig: "~/.kube/config"
      register: mysecret
      ignore_errors: true

So, actual change is namespace: "{{ namespace }}"namespace: "{{ namespace | to_string }}"

Update 21-11-2021 16:35 UTC: it’s wrong solution, actual fix is bellow

There were several documented breaking changes in 2.19. One appears to have been triggered in your code.

You can read about breaking changes in each release in the Changelog:

https://github.com/ansible/ansible/blob/v2.19.0//CHANGELOG-v2.19.rst#breaking-changes-porting-guide

To your point: I agree the error message could be clearer!

1 Like

It’s somewhat weird that you should need a | to_string there.

Out of curiosity, do you get the same error when you use namespace: "test-namespace" in your inventory, another error or does it work then?

@markstos Your link to the Changelog somehow doesn’t work for me, I get 404. ansible/changelogs/CHANGELOG-v2.19.rst at stable-2.19 · ansible/ansible · GitHub does, though.

Maybe the Ansible-core 2.19 Porting Guide might also be helpful.

1 Like

Actually, this to_string was a wrong assumption; it fixed the linter, but not actual playbook :slight_smile: First of all, it should be ansible.builtin.string, not to_string, but the actual issue with the namespace that is a reserved variable name.

So, the actual fix is just rename variable namespace to kube_namespace.

2 Likes