我正在尝试将新的隧道接口附加到空列表中,但出现以下错误。
- name: empty list
set_fact:
list_tunnel: []
- name: create new list for tunnel
set_fact:
list_tunnel_new: "{{ list_tunnel + ['tunnel.{{item}}'] }}"
loop: "{{ range(1,10)|list}}"
Error:
致命:[SJL]:失败! => {"msg": "该任务包含一个带有未定义变量的选项。错误是:'item' 未定义\n\n错误似乎位于 '/etc/ansible/aws/interface_palo_facts.yaml': 行34,第 12 列,但\n可能位于文件中的其他位置,具体取决于具体的语法问题。\n\n有问题的行似乎是:\n\n\n - name: printfacts\n ^ here\n"}
你可以这样做:
- name: create new list for tunnel
set_fact:
list_tunnel: "{{ list_tunnel | default([]) + ['tunnel.' + item | string] }}"
loop: "{{ range(1,10) | list}}"
- debug:
msg: "{{ list_tunnel }}"
or
- set_fact:
list_tunnel: "{{ result }}"
vars:
prefix: tunnel
a_list: "{{ range(1, 10) | list }}"
result: "{{ [prefix] | product(a_list) | map('join', '.') | list }}"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)