Ansible - print gathered facts for debugging purposes

You can simply dump the hostvars:

dump.yml

---
 - name: Dump
   hosts: "{{ target|default('localhost') }}"
   tasks:
   - name: Facts
     setup:
   - name: Dump
     delegate_to: localhost
     run_once: true
     copy:
       content: "{{ hostvars[inventory_hostname] | to_nice_json }}"
       dest: /tmp/setup-dump.json

Call this playbook with ansible-playbook dump.yml -e target=hostname or simply without hostname.


Use setup module as ad-hoc command:

ansible myhost -m setup

Tags:

Ansible