我有这样的任务:
- include: tasks/install_nginx_vhost.yml
vars:
domain_name: learn.{{ domain_name }}
- include: tasks/install_nginx_vhost.yml
vars:
domain_name: author.{{ domain_name }}
但是我收到了这个错误:
recursive loop detected in template string
是否可以暂时(仅限于include)覆盖这样的变量?因为我不想创建其他变量。
答案 0 :(得分:2)
不是。
- set_fact:
learn_domain_name: "learn.{{ domain_name }}"
author_domain_name: "author.{{ domain_name }}"
- include: tasks/install_nginx_vhost.yml
vars:
domain_name: "{{ learn_domain_name }}"
- include: tasks/install_nginx_vhost.yml
vars:
domain_name: "{{ author_domain_name }}"
或更可取,如果可能,您可以将原始domain_name
说明重命名为domain_name_suffix
。然后:
- include: tasks/install_nginx_vhost.yml
vars:
domain_name: learn.{{ domain_name_suffix }}
- include: tasks/install_nginx_vhost.yml
vars:
domain_name: author.{{ domain_name_suffix }}