Considering the following test playbook:
---
- name: Node Tolerations
hosts: localhost
gather_facts: false
vars:
tolerations:
- key: node.cilium.io/agent-not-ready
operator: Exists
effect: NoExecute
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
tasks:
- name: Set node taints fact
ansible.builtin.set_fact:
node_taints: "{{ (node_taints | default([]) | union([':'.join((item.key, item.effect))])) }}"
with_items: '{{ tolerations }}'
- name: Set node toleration fact
ansible.builtin.set_fact:
node_toleration: "{{ node_taints | select('search', 'control-plane') }}"
- name: Variable output
ansible.builtin.debug:
var: node_toleration
Which produces the expected result:
ok: [localhost] =>
node_toleration:
- node-role.kubernetes.io/control-plane:NoSchedule
While using the node_toleration
fact into a Jinja2 template:
node-taint:
{{ node_toleration | indent(2) }}
The following error is generated:
AttributeError: 'list' object has no attribute 'splitlines'
As temporary workaround, I used:
node-taint:
- {{ node_toleration | join }}
But I prefer the initial Jinja2 format, allowing me to define the proper indentation. I was wondering if you can provide some insight, what would be the proper fix.