Ansible高级过滤器三元组

时间:2017-08-24 13:58:17

标签: ansible jinja2

是否有可能在某种程度上同时使用混合字符串和变量的tenary过滤器?我正在考虑参数替换。

  - name: using custom_fact
    shell: "add enet-connection {{item.0.profile_name}} {{ custom_fact is defined | tenary("Speed={{item.1.ansible_facts.custom_fact_key}}", '')}}"
    with_together:
      - "{{enet}}"
      - "{{custom_fact.results}}"

1 个答案:

答案 0 :(得分:1)

(我猜您正在使用te r nary过滤器)

一旦你进入{{ }}部分,你就会编写直接代码:不需要再使用花括号来代替其他变量:

- name: using custom_fact
  shell: "add enet-connection {{item.0.profile_name}} {{ item.1.ansible_facts.custom_fact_key is defined | ternary('Speed=' + item.1.ansible_facts.custom_fact_key, '')}}"
  with_together:
    - "{{enet}}"
    - "{{custom_fact.results}}"