简体   繁体   English

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

[英]Ansible - Get Facts from Remote Windows Hosts

I am using Ansible / Ansible Tower and would like to determine what facts are available on my Windows host. 我正在使用Ansible / Ansible Tower,并想确定Windows主机上可用的事实。 The documentation states that I can run the following: 文档指出,我可以运行以下命令:

ansible hostname -m setup

How would I incorporate this into a playbook I run from Tower so I can gather the information from hosts? 我如何将其合并到从Tower运行的剧本中,以便可以从主机收集信息?

Here is the current Playbook per the assistance given: 这是根据所提供的帮助当前的剧本:

# 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

However, running this produces the following error: 但是,运行它会产生以下错误:

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 此任务“调试”具有额外的参数,仅在以下模块中允许使用:命令,shell,脚本,include,include_vars,add_host,group_by,set_fact,raw,meta

Use gather_facts which is true by default. 使用gather_facts ,默认情况下为true。 It is equivalent to running setup module. 它等效于运行setup模块。

- hosts: ....
  gather_facts: yes

The facts are saved in ansible variables to be used in playbooks. 事实被保存在ansible变量中,以便在剧本中使用。 See System Facts 查看系统事实

There are many ways to display the ansible facts. 有很多显示不可思议事实的方法。 For you to understand how it works, try the following: 为了让您了解其工作原理,请尝试以下操作:

- hosts: 127.0.0.1
  gather_facts: true

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

Testing and working through it, this is working for me: 测试并完成它,这对我来说是有效的:

- name: Gather Windows Facts 
  hosts: "{{ target }}"
  tasks:
    - debug: var=vars
    - debug: var=hostvars[inventory_hostname]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM