Ansible:使模板使用在不同文件中为不同运行定义的变量
我在剧本中有一个任务,如图所示:Ansible:使模板使用在不同文件中为不同运行定义的变量,ansible,Ansible,我在剧本中有一个任务,如图所示: - name: Create configuration.json for every analytics from the template. template: src: ./src-zip/{{ item.key }}/configuration_sample.j2 dest: ./src-zip/{{ item.key }}/configuration.json with_dict: "{{ apps }}" 现在,我在文件中为
- name: Create configuration.json for every analytics from the template.
template:
src: ./src-zip/{{ item.key }}/configuration_sample.j2
dest: ./src-zip/{{ item.key }}/configuration.json
with_dict: "{{ apps }}"
现在,我在文件中为每次运行定义了一些通用变量和一些不同变量
比如,一次运行就有文件var\u alerts-manager.yml
。
对于另一次运行,我有var_abc.yml
现在我想为不同的运行使用不同的文件。换句话说,模板将在一次运行中使用var_alerts-manager.yml
中定义的变量,在另一次运行中使用abc.yml
中定义的变量,依此类推
如何在ansible中实现这一点?我应该将这些文件保存在何处,以便每次运行时任务只能包含该特定文件?这是角色机制演变的场景:
my_角色
角色vars
目录中- name: Create configuration.json for every analytics from the template.
include_role:
name: my_role
vars_from: "{{ item.key }}" # or whatever key your naming is defined in
loop: "{{ apps|dict2items }}"
您可能希望用其他变量替换模板任务中的
项
,为清楚起见,请阅读。这是角色机制演变的场景:
my_角色
角色vars
目录中- name: Create configuration.json for every analytics from the template.
include_role:
name: my_role
vars_from: "{{ item.key }}" # or whatever key your naming is defined in
loop: "{{ apps|dict2items }}"
项
,为清楚起见,请阅读