Ansible - 从远程 Windows 主机获取信息

4

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

ansible hostname -m setup

我该如何将这个内容加入到我从Ansible Tower运行的playbook中,以便我可以从主机收集信息?
以下是根据给出的帮助编写的当前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
2个回答

5

使用默认为真的gather_facts。它相当于运行setup模块。

- hosts: ....
  gather_facts: yes

事实保存在ansible变量中,以便在playbook中使用。请参见System Facts
有许多方法可以显示ansible事实。为了让您了解它的工作原理,请尝试以下操作:
- hosts: 127.0.0.1
  gather_facts: true

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

输出显示在哪里?我该如何使其输出? - Kode
有没有一种方法可以输出大型列表,以便我知道变量是什么?在他们的示例中,它提供了一个大型Ubuntu输出。通过这些列出的内容,我现在可以知道可以用作变量的内容。这里列出了一个fact_path,但不确定在playbook中如何使用http://docs.ansible.com/ansible/setup_module.html - Kode
在-debug上收到一个错误(Playbooks的新功能):有问题的行似乎是:register: ansible_facts
  • debug: item ^ 这里
- Kode
发布你的剧本或者尝试我发布的那个。 - helloV
完成,我有一个 gather_facts: yes,而你有 true。 - Kode

0

测试并逐步解决问题,这对我有效:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接