基于一个变量,我需要两个版本的“相同”列表,我想避免重复如下代码:
- set_fact:
type1: false (or true!)
- set_fact:
mylist:
- "show command1"
- "show command2.1"
- "show command3"
- "show command4"
when: type1
- set_fact:
mylist:
- "show command1"
- "show command2.1"
- "show command2.2"
- "show command3"
- "show command4"
when: not type1
有没有办法(Jinja?)避免重复?
里卡多·鲁索
我目前的解决方案是:
mycmd:
- "show command1"
- "show command2.1"
{% if not type1 %}
- "show command2.2"
{% endif %}
- "show command3"
- "show command4"
- set_fact:
myvar: "{{ lookup('template', './mytemplate.j2') | from_yaml }}"
- debug:
var: myvar["cmd"]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句