gpt4 book ai didi

ubuntu - ansible playbook 变量的值如何在另一个 paybook 中使用?

转载 作者:行者123 更新时间:2023-12-04 18:43:58 27 4
gpt4 key购买 nike

我有两个不同的剧本,分别命名为 demo1.yml demo2.yml
demo1.yml 中有一个播放,播放的返回值存储在名为 结果 的寄存器变量中。变量 结果 具有以下内容:

"volume_details": {
"status": "Ready",
"Id": "123456",
"name": "test_volume"
}
我想在另一个剧本 demo2.yml 的其中一个剧本中使用 results.volume_details.Idresults.volume_details.name 的值。
有什么办法可以将以前剧本中的变量值用于另一个即将到来的剧本。我要提前感谢您的努力!!!

最佳答案

您可以创建一个主要剧本并使用 import_playbook 导入其他剧本

---
- import_playbook: demo1.yml
- import_playbook: demo2.yml
如果这样做,应该可以在第二个剧本的任务中使用第一个剧本中的注册变量。与 {{ results.volume_details }}编辑:
要将变量保存到文件中,您可以使用带有参数 content= 的复制模块。
 - copy: 
content="{{ variable }}"
dest=dest_file.yml

要加载此文件,请使用 include_var模块
- name: Include var of dest_file.yml into the new_var 
include_vars:
file: dest_file.yml
name: new_var

关于ubuntu - ansible playbook 变量的值如何在另一个 paybook 中使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62533985/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com