有人能解释 Ansible 中的以下 Jinja 行为吗?
以下代码有效:跳过该任务,因为 job_function 不在 rejection_functions 数组中
- name: Lowercase test
hosts: localhost
gather_facts: false
vars:
job_function: 'VRIJwillig'
exclusion_functions:
- vrijwilliger
- maatje
tasks:
- name: Test for function in exclusions
debug:
msg: In exclusions
when: (job_function | lower) in exclusion_functions
以下代码同样有效,第二个任务被跳过。
- name: Lowercase test
hosts: localhost
gather_facts: false
vars:
job_function: 'VRIJwillig'
exclusion_functions:
- Vrijwilliger
- Maatje
tasks:
- name: Initialiseer variabelen
set_fact:
exclusions: "{{ exclusion_functions | lower }}"
- name: Test for function in exclusions
debug:
msg: In exclusions
when: (job_function | lower) in exclusions
但这不起作用,任务没有被跳过:
---
- name: Lowercase test
hosts: localhost
gather_facts: false
vars:
job_function: 'VRIJwillig'
exclusion_functions:
- Vrijwilliger
- Maatje
tasks:
- name: Test for function in exclusions
debug:
msg: In exclusions
when: (job_function | lower) in (exclusion_functions | lower)
为什么在最后一段代码中没有跳过任务?job_function | lower
是vrijwillig
,并且exclusion_functions | lower
是['vrijwilliger','maatje']
,而第一个不在第二个中。