2016-08-15 372 views
0

我正在使用Ansible/Ansible Tower,並想確定Windows主機上有哪些可用的事實。該documentation狀態,我可以運行以下命令:Ansible - 從遠程Windows主機獲取事實

ansible hostname -m setup 

我將如何納入一個劇本,我從塔運行這個,所以我可以收集來自主機的相關信息?

這裏是按所給的援助,目前的劇本:

# 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

使用gather_facts默認爲真。它相當於運行setup模塊。

- hosts: .... 
    gather_facts: yes 

事實保存在可用的變量中以用於劇本。請參閱System Facts

有許多方法可以顯示事實。讓你瞭解它是如何工作的,請嘗試以下操作:

- hosts: 127.0.0.1 
    gather_facts: true 

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

哪裏輸出顯示/我怎麼得到這個輸出? – Kode

+1

@Kode看到我的更新。 – helloV

+0

有沒有辦法輸出大的列表,所以我知道變量是什麼?在他們的例子中,它提供了大量的Ubuntu輸出。有了這些列表,我現在可以知道我可以用作變量了。這裏列出了一個fact_path,但不確定這是如何工作在劇本中http://docs.ansible.com/ansible/setup_module.html – Kode

0

測試,並通過它的工作,這是爲我工作:

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