Ansible - 打印收集的事实以进行调试

时间:2018-04-05 16:48:41

标签: ansible

是否存在某种方式在控制台收集的事实上打印?
我的意思是使用setup模块来提供事实。我想打印收集到的事实。可能吗 ?如果有可能有人展示例子吗?

2 个答案:

答案 0 :(得分:13)

setup模块用作ad-hoc命令:

ansible myhost -m setup

答案 1 :(得分:3)

您只需转储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

使用ansible-playbook dump.yml -e target=hostname或只是没有主机名称来调用此剧本。