任务:用Ansible-Playbook从主机组收集事实,然后将它们放入本地计算机上的文件中。
我的解决方案:
---
- hosts: foo
order: sorted
gather_facts: no
remote_user: foo
become: yes
become_method: sudo
tasks:
- name: gather foo hosts information
setup:
register: gathered_data
- name: write gathered information into a file
local_action: copy content="{{ gathered_data }}" dest=/foo/gathered_data.out
...
问题:一切正常,但是输出文件是一条巨大的线路。是否可以像ansible -m setup foo
输出一样继续文本格式?
还为此任务寻找更好的解决方案。Ansible版本:2.4.2.0
您可以使用其中一个过滤器进行格式化数据,例如:
content: "{{ gathered_data | to_nice_json }}”