Red_Hat
EX294 · Question #13
13. Generating Hardware Report Create a playbook named /home/greg/ansible/hwreport.yml that will generate an output file /root/hwreport.txt containing the following information on all managed nodes…
The task requires an Ansible playbook to gather specific hardware facts from managed nodes and generate a formatted report file /root/hwreport.txt, handling missing data gracefully.
Submitted by kim_seoul· Apr 18, 2026Manage Variables, Facts, and Content
Question
- Generating Hardware Report Create a playbook named /home/greg/ansible/hwreport.yml that will generate an output file /root/hwreport.txt containing the following information on all managed nodes: Inventory host name Total memory size in MB BIOS version Size of disk device vda Size of disk device vdb Each line in the output file should contain a key=value pair. Your playbook should: - Replace the placeholders in /root/hwreport.txt with the correct values. - If a hardware item does not exist, its related value should be set to NONE. Correct Answer: See the below explanation Explanation Explanation/Reference: Solution: [greg@control ansible]$ ansible all -m setup | grep mem [greg@control ansible]$ ansible all -m setup | grep bios [greg@control ansible]$ ansible all -m setup -a 'filter=device' [greg@control ansible]$ vim /home/greg/ansible/hwreport.yml --- - name: Hardware report hosts: all tasks: - name: Download hwreport ansible.builtin.get_url: dest: /root/hwreport.txt - name: Report 1 ansible.builtin.lineinfile: ansible.builtin.lineinfile: path: /root/hwreport.txt regexp: '^MEMORY=' line: MEMORY={{ ansible_memtotal_mb }} - name: Report 3 ansible.builtin.lineinfile: path: /root/hwreport.txt regexp: '^BIOS=' line: BIOS={{ ansible_bios_version }} - name: Report 4 ansible.builtin.lineinfile: path: /root/hwreport.txt regexp: '^DISK_SIZE_VDA=' line: DISK_SIZE_VDA={{ ansible_devices.vda.size }} - name: Report 5 ansible.builtin.lineinfile: path: /root/hwreport.txt regexp: '^DISK_SIZE_VDB=' line: DISK_SIZE_VDB={{ ansible_devices.vdb.size | default('NONE', true) }} # Verification: The collected reports should match the facts from each host. Please verify them manually. (mandatory operation) [greg@control ansible]$ ansible-navigator run hwreport.yml -m stdout [greg@control ansible]$ ansible all -a 'cat /root/hwreport.txt'
Explanation
The task requires an Ansible playbook to gather specific hardware facts from managed nodes and generate a formatted report file /root/hwreport.txt, handling missing data gracefully.
Concept tested. Ansible fact gathering, Jinja2 templating, file manipulation
Reference. https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html
Topics
#Ansible Facts#Playbook Creation#File Manipulation#Jinja2 Filters
Community Discussion
No community discussion yet for this question.