1、先写一个模板
[[email protected] ansible]$ vim hwhosts.yml
---
- name: create /mnt/hwhosts
hosts: all
tasks:
- name: use templates
template:
src: templates/hwhosts.j2
dest: /mnt/hwhosts ##采集的信息在客户机此文件中
[[email protected] ansible]$ ansible-playbook --syntax-check hwhosts.yml ##检测语法
playbook: hwhosts.yml
2、写入要采集的信息
[[email protected] ansible]$ mkdir templates
[[email protected] ansible]$ vim templates/hwhosts.j2 ##在此文件写入要采集的信息
hostname: {{ ansible_facts['hostname'] }}
system: {{ ansible_facts['distribution'] }}
kernel: {{ ansible_facts['kernel'] }}
3、执行
[[email protected] ansible]$ ansible-playbook hwhosts.yml ##推的是模板

4、查看
