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
10 months agoFlorinda
10 months agoLavonna
11 months agoTheron
11 months agoVanna
11 months agoPenney
11 months agoHaydee
11 months agoRosalia
11 months agoAbel
11 months agoBelen
11 months agoGail
11 months agoAlexis
11 months agoKirby
11 months agoStephaine
11 months agoPolly
11 months agoCherelle
12 months ago