RedHat EX294 Exam - Topic 17 Question 13 Discussion
Create a playbook called hwreport.yml that produces an output file called /root/hwreport.txt on all managed nodes with the following information:--------------------------------------------------------------------------------------------------------> Inventory host name--> Total memory in MB--> BIOS version--> Size of disk device vda--> Size of disk device vdbEach line of the output file contains a single key-value pair.* Your playbook should:hwreport.empty andsave it as /root/hwreport.txt--> Modify with the correct values.note: If a hardware item does not exist, the associated value should be set to NONE----------------------------------------------------------------------------------------------while practising you to create these file hear. But in exam have to download as perquestation.hwreport.txt file consists.my_sys=hostnamemy_BIOS=biosversionmy_MEMORY=memorymy_vda=vdasizemy_vdb=vdbsize
A) Explanation:
Solution as:
# pwd
/home/admin/ansible
# vim hwreport.yml
- name:
hosts: all
ignore_errors: yes
tasks:
- name: download file
get_url:
url: http://classroom.example.com/content/ex407/hwreport.empty
dest: /root/hwreport.txt
- name: vdasize
replace:
regexp: 'vdasize'
replace: '{{ ansible_facts.devices.vda.size }}'
dest: /root/hwreport.txt
register: op1
- debug:
var: op1
- name: none
replace:
regexp: 'vdasize'
replace: NONE
dest: /root/hwreport.txt
when:
op1.failed == true
- name: vdbsize
replace:
regexp: 'vdbsize'
replace: '{{ ansible_facts.devices.vdb.size }}'
dest: /root/hwreport.txt
register: op2
- debug:
var: op2
- name: none
replace:
regexp: 'vdbsize'
replace: NONE
dest: /root/hwreport.txt
when:
op2.failed == true
- name: sysinfo
replace:
regexp: '{{item.src}}'
replace: '{{item.dest}}'
dest: /root/hwreport.txt
loop:
- src: 'hostname'
dest: '{{ ansible_facts.fqdn }}'
- src: 'biosversion'
dest: '{{ ansible_facts.bios_version }}'
- src: 'memory'
dest: '{{ ansible_facts.memtotal_mb }}'
:wq!
# ansible-playbook hwreport.yml ---syntax-check
# ansible-playbook hwreport.yml
Rikki
8 months agoFlorinda
8 months agoLavonna
9 months agoTheron
9 months agoVanna
9 months agoPenney
9 months agoHaydee
9 months agoRosalia
9 months agoAbel
9 months agoBelen
9 months agoGail
9 months agoAlexis
9 months agoKirby
9 months agoStephaine
9 months agoPolly
10 months agoCherelle
10 months ago