在ansible中将变量文件导入另一个文件 [英] import an variable file to another in ansible
本文介绍了在ansible中将变量文件导入另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 ansible 的新手.我有 2 个变量文件,一个是全局的,另一个是特定于环境的.这是 global/group_var/all.yaml 文件夹中的全局一个:
I am new to ansible. I have 2 variable files one is global and another is environment specific. Here is the global one in global/group_var/all.yaml folder:
rel:
deployment:
webui:
dockerName: "rel"
dockerTag: "Dev_{{ travis.build_number }}"
具体的在develop/group_var/all.yaml文件夹中
And the specific one is in develop/group_var/all.yaml folder
docker:
registery: "xxxx"
有什么办法可以将 global/group_var/all.yaml 导入到 development/group_var/all.yaml
is there any way I can import global/group_var/all.yaml to develop/group_var/all.yaml
import global/group_var/all.yaml
docker:
registery: "xxxx"
所以 develop/group_var/all.yaml 变成:
so develop/group_var/all.yaml becomes:
rel:
deployment:
webui:
dockerName: "rel"
docker:
registery: "xxxx"
dockerTag: "Dev_1111"
谢谢
推荐答案
可以将全局变量读入字典.例如
It's possible to read the global variables into a dictionary. For example
$ cat develop/group_var/all.yaml
global: "{{ lookup('file', 'global/group_var/all.yaml')|from_yaml }}"
docker:
registery: "xxxx"
剧本
- hosts: localhost
tasks:
- include_vars: develop/group_var/all.yaml
- debug:
var: global
- debug:
var: docker
给予
"global": {
"rel": {
"deployment": {
"webui": {
"dockerName": "rel"
}
}
}
}
"docker": {
"registery": "xxxx"
}
这篇关于在ansible中将变量文件导入另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文