问题
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 }}"
And the specific one is in develop/group_var/all.yaml folder
docker:
registery: "xxxx"
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"
so develop/group_var/all.yaml becomes:
rel:
deployment:
webui:
dockerName: "rel"
docker:
registery: "xxxx"
dockerTag: "Dev_1111"
Thanks
回答1:
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"
the playbook
- hosts: localhost
tasks:
- include_vars: develop/group_var/all.yaml
- debug:
var: global
- debug:
var: docker
gives
"global": {
"rel": {
"deployment": {
"webui": {
"dockerName": "rel"
}
}
}
}
"docker": {
"registery": "xxxx"
}
来源:https://stackoverflow.com/questions/59794199/import-an-variable-file-to-another-in-ansible