考虑到以下试验游戏手册:
---
- 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 tolerations fact
ansible.builtin.set_fact:
node_tolerations: "{{ (node_tolerations | default([]) | union([ : .join((item.key, item.effect))])) }}"
with_items: {{ tolerations }}
- name: Set node taint fact
ansible.builtin.set_fact:
node_taint: "{{ node_tolerations | select( search , control-plane ) }}"
- name: Variable output
ansible.builtin.debug:
var: node_taint
产生预期结果:
ok: [localhost] =>
node_taint:
- node-role.kubernetes.io/control-plane:NoSchedule
使用<代码>node_taint a. 列入Jinja2模板的事实:
node-taint:
{{ node_taint | indent(2) }}
产生以下错误:
AttributeError: list object has no attribute splitlines
As temporary workaround, I used:
node-taint:
- {{ node_taint | join }}
但是,我倾向于最初的金贾2格式,允许我界定适当的诱惑。 我很想知道,你是否能够提供一些见解,什么是适当的解决办法。
Edit: 上文详细游戏手册的第二次使用是:
tolerations:
{{ tolerations | indent(2) }}
产生同样的错误。 我更希望避免在金贾模板中使用<条码>(<>>>>格式,并在事实上操纵数据,使我能够在模板内使用适当的<条码>indent。