Ansible 如何“注册"?在变量中包含剧本的结果? [英] How can Ansible "register" in a variable the result of including a playbook?
问题描述
Ansible 剧本如何register
在一个变量中 包括另一本剧本?
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屋!