0%

RHCE (EX294) - 生成硬件报告

生成硬件报告

创建一个名为 /home/greg/ansible/hwreport.yml 的 playbook,它将在所有受管节点上生成含有以下信息的输出文件 /root/hwreport.txt

清单主机名称

MB 表示的 总内存大小

BIOS 版本

磁盘设备 vda 的大小

磁盘设备 vdb 的大小

输出文件中的每一行含有一个 key=value 对

您的 playbook 应当:

http://materials/hwreport.empty 下载文件,并将它保存为 /root/hwreport.txt

使用 正确的值 改为 /root/hwreport.txt

如果硬件项不存在,相关的值应设为 NONE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[greg@control ansible]$ vim /home/greg/ansible/hwreport.yml
---
- name: 生成硬件报告
hosts: all
tasks:
- name: Download hwreport.txt
get_url:
url: http://materials/hwreport.empty
dest: /root/hwreport.txt
- name: Ensure HOST
lineinfile:
path: /root/hwreport.txt
regexp: '^HOST='
line: HOST={{ inventory_hostname }}
- name: Ensure MEMORY
lineinfile:
path: /root/hwreport.txt
regexp: '^MEMORY='
line: MEMORY={{ ansible_facts['memtotal_mb'] }}
- name: Ensure BIOS
lineinfile:
path: /root/hwreport.txt
regexp: '^BIOS='
line: BIOS={{ ansible_facts['bios_version'] }}
- name: Ensure DISK_SIZE_VDA
lineinfile:
path: /root/hwreport.txt
regexp: '^DISK_SIZE_VDA='
line: DISK_SIZE_VDA={{ ansible_facts['devices']['vda']['size'] | default('NONE',true) }}
- name: Ensure DISK_SIZE_VDB
lineinfile:
path: /root/hwreport.txt
regexp: '^DISK_SIZE_VDB='
line: DISK_SIZE_VDB={{ ansible_facts['devices']['vdb']['size'] | default('NONE',true) }}
[greg@control ansible]$ ansible-playbook hwreport.yml
[greg@control ansible]$ ansible all -a 'cat /root/hwreport.txt'