Ansible如何“注册"?在变量中包含剧本的结果? [英] How can Ansible "register" in a variable the result of including a playbook?
问题描述
How can an Ansible playbook register
in a variable the result of including another playbook?
例如,以下代码会在result_of_foo
中注册执行tasks/foo.yml
的结果吗?
For example, would the following register the result of executing tasks/foo.yml
in result_of_foo
?
tasks:
- include: tasks/foo.yml
- register: result_of_foo
Ansible还能如何记录任务序列的结果?
How else can Ansible record the result of a task sequence?
推荐答案
简短的答案是这无法完成.
The short answer is that this can't be done.
register 语句用于存储单个输出任务变成一个变量.根据任务的类型,已注册变量的确切内容可能相差很大(例如,shell
任务将包括您在已注册变量中运行的命令的stdout&stderr输出,而stat
任务将提供详细信息传递给任务的文件的名称).
The register statement is used to store the output of a single task into a variable. The exact contents of the registered variable can vary widely depending on the type of task (for example a shell
task will include stdout & stderr output from the command you run in the registered variable, while the stat
task will provide details of the file that is passed to the task).
如果您的包含文件中包含任意数量的任务,那么Ansible将无法知道示例中存储在变量中的内容.
If you have an include file with an arbitrary number of tasks within it then Ansible would have no way of knowing what to store in the variable in your example.
包含文件中的每个任务都可以注册变量,并且可以在其他位置引用这些变量,因此实际上甚至不需要执行这样的操作.
Each individual task within your include file can register variables, and you can reference those variables elsewhere, so there's really no need to even do something like this.
这篇关于Ansible如何“注册"?在变量中包含剧本的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!