生成硬件报告
创建一个名为 /home/curtis/ansible/hwreport.yml 的 playbook ,它将在所有受管节点上生成含有以下信息的输出文件 /root/hwreport.txt :
清单主机名称
以 MB 表示的总内存大小
BIOS 版本
磁盘设备 vda 的大小
磁盘设备 vdb 的大小
输出文件中的每一行含有一个 key=value 对。
您的 playbook 应当:
从 http://rhgls.area12.example.com/materials/hwreport.empty 下载文件,并将它保存为 /root/hwreport.txt
使用正确的值改为 /root/hwreport.txt
如果硬件项不存在,相关的值应设为 NONE
wget http://rhgls.area12.example.com/materials/hwreport.empty
cat hwreport.empty
vim hwreport.yml
- hosts: all
tasks:
- get_url:
url: http://rhgls.area12.example.com/materials/hwreport.empty
dest: /root/hwreport.txt
- replace:
path: /root/hwreport.txt
regexp: inventoryhostname
replace: "{{ ansible_hostname | default (none)}}"
- replace:
path: /root/hwreport.txt
regexp: memory_in_MB
replace: "{{ ansible_memtotal_mb | default (none)}}"
- replace:
path: /root/hwreport.txt
regexp: BIOS_version
replace: "{{ ansible_bios_version | default (none)}}"
- replace:
path: /root/hwreport.txt
regexp: disk_vda_size
replace: "{{ ansible_devices.vda.size | default (none)}}"
- replace:
path: /root/hwreport.txt
regexp: disk_vdb_size
replace: "{{ ansible_devices.vdb.size | default (none)}}"
ansible-playbook hwreport.yml