What Should I know About The RHCE Exam
RHCE 8 EX294 exam practice question 2
Question
Because you will have to install software on the managed hosts, you need to do the following:
*Create a shell script with the name packages.sh that runs an Ansible ad-hoc command to create a yum repository on all managed hosts using the information as below:
-The Appstream base URL and BaseOS URL are “http://hqdev1.tekneed.com/rpm/AppStream” and “http://hqdev1.tekneed.com/rpm/BaseOS”
-The Appstream and BaseOS description are “RHEL 8 Appstream” and “RHEL 8 BaseOS”
-The Appstream and BaseOS names are “RHEL_Appstream” “RHEL_BaseOS”
-The repositories must be enabled with a gpgkey of http://hqdev1.tekneed.com/rpm/RPM-GPG-KEY-redhat-release
This question is based on understanding and using the Ansible ad hoc command in the RHCE 8/EX294 course on this website. If you have gone through this course, solving this wouldn’t be a problem.
Understanding and using the ansible ad hoc command
Answer
1. Create the packages.sh file, and use the yum_repository module.
[lisa@drdev1 ~]$ vim /home/lisa/ansible/packages.sh
#!/bin/bash
ansible all -m yum_repository -a 'baseurl=http://hqdev1.tekneed.com/rpm/AppStream description="RHEL 8 Appstream" name=RHEL_Appstream enabled=1 gpgcheck=1 gpgkey=http://hqdev1.tekneed.com/rpm/RPM-GPG-KEY-redhat-release file=rhel'
ansible all -m yum_repository -a 'baseurl=http://hqdev1.tekneed.com/rpm/BaseOS description="RHEL 8 BaseOS" name=RHEL_BaseOS enabled=1 gpgcheck=1 gpgkey=http://hqdev1.tekneed.com/rpm/RPM-GPG-KEY-redhat-release file=rhel'
2. Make the file executable
[lisa@drdev1 ~]$ chmod 667 /home/lisa/ansible/packages.sh
3. Verify that the file is executable.
[lisa@drdev1 ~]$ ls -l /home/lisa/ansible/packages.sh
-rw-rw-rwx. 1 lisa lisa 438 Jun 16 11:14 /home/lisa/ansible/packages.sh
4. Run the script.
[lisa@drdev1 ~]$ cd /home/lisa/ansible/
[lisa@drdev1 ansible]$ sudo ./packages.sh
.............
hqdev1.tekneed.com | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"repo": "RHEL_BaseOS",
"state": "present"
..............
5. Verify your configuration
*since hqdev1.tekneed.com is among the managed hosts, one can use the ansible adhoc command to verify that the yum repository file was created on the host.
[lisa@drdev1 ansible]$ ansible hqdev1.tekneed.com -a 'cat /etc/yum.repos.d/rhel.repo'
hqdev1.tekneed.com | CHANGED | rc=0 >>
[RHEL_Appstream]
baseurl = http://hqdev1.tekneed.com/rpm/AppStream
enabled = 1
gpgcheck = 1
gpgkey = http://hqdev1.tekneed.com/rpm/RPM-GPG-KEY-redhat-release
name = RHEL 8 Appstream
[RHEL_BaseOS]
baseurl = http://hqdev1.tekneed.com/rpm/BaseOS
enabled = 1
gpgcheck = 1
gpgkey = http://hqdev1.tekneed.com/rpm/RPM-GPG-KEY-redhat-release
name = RHEL 8 BaseOS
NOTE
If gpgkeys are not given in the question, the packages.sh script will be written as below.
#!/bin/bash
ansible all -m yum_repository -a 'baseurl=http://hqdev1.tekneed.com/rpm/AppStream description="RHEL 8 Appstream" name=RHEL_Appstream enabled=1 gpgkey=0 file=rhel'
ansible all -m yum_repository -a 'baseurl=http://hqdev1.tekneed.com/rpm/BaseOS description="RHEL 8 BaseOS" name=RHEL_BaseOS enabled=1 gpgkey=0 file=rhel'
The script can also be written as below;
#!/bin/bash
ansible all -m yum_repository -a 'baseurl=http://hqdev1.tekneed.com/rpm/AppStream description="RHEL 8 Appstream" name=RHEL_Appstream enabled=1 gpgcheck=1 gpgkey=http://hqdev1.tekneed.com/rpm/RPM-GPG-KEY-redhat-release file=rhel'
ansible all -m yum_repository -a 'baseurl=http://hqdev1.tekneed.com/rpm/BaseOS description="RHEL 8 BaseOS" name=RHEL_BaseOS enabled=1 gpgcheck=1 gpgkey=http://hqdev1.tekneed.com/rpm/RPM-GPG-KEY-redhat-release file=rhel'
ansible all -m rpm_key -a 'key=http://hqdev1.tekneed.com/rpm/RPM-GPG-KEY-redhat-release stat
e=present'
Solution Summary
vim /home/lisa/ansible/packages.sh
chmod 667 /home/lisa/ansible/packages.sh
cd /home/lisa/ansible
./packages.sh
click on the link below to watch video on RHCE 8 EX294 exam practice question 2
Watch Video On RHCE 8 EX294 Exam Practice Question 2
Watch Video On Ansible Installation In Linux
Your feedback is welcomed. If you love others, you will share with others
“If gpgkeys are not given in the question, the packages.sh script will be written as below.”
Shouldn’t it be gpgcheck=0 insted gpgkey=0?