gpt4 book ai didi

Ansible - 从远程 Windows 主机获取事实

转载 作者:行者123 更新时间:2023-12-05 02:20:32 24 4
gpt4 key购买 nike

我正在使用 Ansible/Ansible Tower 并想确定我的 Windows 主机上有哪些可用信息。 documentation声明我可以运行以下命令:

ansible hostname -m setup

我如何将其合并到我从 Tower 运行的剧本中,以便我可以从主机收集信息?

根据所提供的帮助,这是当前的 Playbook:

# This play outputs the facts of the Windows targets in scope

- name: Gather Windows Facts
hosts: "{{ target }}"
gather_facts: yes
tasks:
- setup:
register: ansible_facts
- debug: item
with_dict: ansible_facts

但是,运行它会产生以下错误:

ERROR! this task 'debug' has extra params, which is only allowed in the following modules: command, shell, script, include, include_vars, add_host, group_by, set_fact, raw, meta

最佳答案

使用 gather_facts 默认情况下为真。相当于运行setup模块。

- hosts: ....
gather_facts: yes

事实被保存在 ansible 变量中以在剧本中使用。参见 System Facts

有很多方法可以显示ansible facts。为了解其工作原理,请尝试以下操作:

- hosts: 127.0.0.1
gather_facts: true

tasks:
- setup:
register: ansible_facts
- debug: item
with_dict: ansible_facts

关于Ansible - 从远程 Windows 主机获取事实,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38962577/

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