【发布时间】:2018-07-03 22:20:59
【问题描述】:
我正在编写一个 ansible 自定义模块,它与 URI 模块具有一些附加功能。 特别是,我希望返回的数据可以作为全局变量或主机特定变量 (其中主机是运行任务的清单主机)。 基于传递给模块的值。
但是,无论我做什么似乎都只能创建一个全局变量。 假设我为 N 个主机运行 playbook,并且只执行一次自定义模块(run_once:是)。
[...]
- name: Run the custom module and generate output in custom_var
run_once: yes
custom_module:
field1: ...
field2: ...
global_data: yes -> yes, to create a global fact called: custom_var
- name: DEBUG - Print the content of custom_var
debug: msg="{{ custom_var }}"
这很好用,所有 N 个主机都可以看到 custom_var。 有没有办法只为执行任务的实际主机定义 custom_var?
奇怪的是,我还尝试注册第一个任务的结果如下:
[...]
- name: Run the custom module and generate output in custom_var
run_once: yes
custom_module:
field1: ...
field2: ...
global_data: no -> no, if I don't create any global fact
register: register_task
- name: DEBUG - Print the content of custom_var
debug: msg="{{ register_task }}"
但看起来这也适用于清单中的所有主机(具有相同的内容)。这是预期的行为吗? 还有关于如何使 custom_var 仅可用于实际运行任务的主机的任何想法?
提前致谢!
【问题讨论】:
-
我在您的问题中看不到任何代码。 stackoverflow.com/help/mcve
标签: ansible ansible-facts