繁体   English   中英

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

[英]Ansible - Get Facts from Remote Windows Hosts

我正在使用Ansible / Ansible Tower,并想确定Windows主机上可用的事实。 文档指出,我可以运行以下命令:

ansible hostname -m setup

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

这是根据所提供的帮助当前的剧本:

# 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

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

错误! 此任务“调试”具有额外的参数,仅在以下模块中允许使用:命令,shell,脚本,include,include_vars,add_host,group_by,set_fact,raw,meta

使用gather_facts ,默认情况下为true。 它等效于运行setup模块。

- hosts: ....
  gather_facts: yes

事实被保存在ansible变量中,以便在剧本中使用。 查看系统事实

有很多显示不可思议事实的方法。 为了让您了解其工作原理,请尝试以下操作:

- hosts: 127.0.0.1
  gather_facts: true

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

测试并完成它,这对我来说是有效的:

- 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