Kode
Kode

Reputation: 3215

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. The documentation states that I can run the following:

ansible hostname -m setup

How would I incorporate this into a playbook I run from Ansible Tower so I can gather the information from hosts?

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

Upvotes: 4

Views: 20549

Answers (2)

Kode
Kode

Reputation: 3215

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]

Upvotes: 0

helloV
helloV

Reputation: 52423

Use gather_facts which is true by default. It is equivalent to running setup module.

- hosts: ....
  gather_facts: yes

The facts are saved in ansible variables to be used in playbooks. 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

Upvotes: 5

Related Questions