【发布时间】:2020-06-05 05:44:43
【问题描述】:
我正在尝试使用Python API从所有可能的位置提取variables
在我的剧本test_play.yml 我有..
---
hosts: abc.com
gather_facts: no
roles:
- my_roles
vars_files:
- var/var.yml
tasks:
.....
.....
文件结构-
test_play.yml
roles
- my_roles
-- defaults
vars
- var.yml
hosts
- DEV
-- hosts
-- group_vars
--- all.yml
我的代码——
host_file = path_to_host_file
play_path = path_to_playbook
inventory = InventoryManager(loader=DataLoader(), source=[host_file])
variable_manager = VariableManager(loader=DataLoader(), inventory=inventory)
pb = Playbook.load(play_path, variable_manager, DataLoader())
play = pb.get_plays()
# here I get one play, which is fine
all_vars = variable_manager.get_vars(play=plays[0])
在all_vars 中,我只得到在inventory file, rules 中定义的变量。但是var.yml, group_vars/all.yml 中定义的变量丢失了。如何获得?
【问题讨论】:
-
我也有同样的问题;有什么想法吗?
标签: python ansible ansible-inventory