是否可以在Ansible中组合单独的Vars文件中提到的相同变量名称的值
和app2.yml
具有相同的变量名称,
cat app1.yml
dbconn:
- host1 port1
cat app2.yml
dbconn:
- host4 port4
- host5 port5
我有两个变量文件app1.yml
- name: Load Variable Files
include_vars: "{{ playbook_dir }}/{{ item }}.yml"
loop:
- app1
- app2
run_once: yes
- debug:
msg: "{{ dbconn }}"
即代码> dbconn 具有来自两个变量文件的值,即
- host1 port1
- host4 port4
- host5 port5
,它仅打印最后加载的变量文件值IE -OSTOR4 port4 port4
and - host5 port5
您可以建议吗?
I have two variable files app1.yml
and app2.yml
having the same variable name viz dbconn
cat app1.yml
dbconn:
- host1 port1
cat app2.yml
dbconn:
- host4 port4
- host5 port5
cat main.yml
- name: Load Variable Files
include_vars: "{{ playbook_dir }}/{{ item }}.yml"
loop:
- app1
- app2
run_once: yes
- debug:
msg: "{{ dbconn }}"
My expectation is that variable dbconn
to have values from both the variable files i.e
- host1 port1
- host4 port4
- host5 port5
However, it prints only the last loaded variable file values i.e - host4 port4
and - host5 port5
Can you please suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
加入循环中的列表。例如,
给予
Concatenate the lists in the loop. For example,
gives
您有一个特定的问题,因此本剧本是解决您的问题的解决方案:
第一个任务给出了变量:
第二个任务concats一个列表中的所有列表
dbConn:
最终结果:
you have a specific problem so this playbook is a solution to resolve your problem:
the first task gives as variables:
and the second task concats all lists in one list
dbconn:
final result: