Deploying Files
- "Do I Know This Already?" Quiz
- Using Modules to Manipulate Files
- Managing SELinux Properties
- Using Jinja2 Templates
- Summary
- Exam Preparation Tasks
- Review All Key Topics
- Memory Tables
- Define Key Terms
- Review Questions
- Exercise Answers
- Lab 8-1: Generate an /etc/hosts File
- Lab 8-2: Manage a vsftpd Service
In this sample chapter from Red Hat RHCE 8 (EX294) Cert Guide, you will learn how to use modules to manipulate files, manage SELinux properties, and use Jinja2 templates.
This chapter covers the following subjects:
Using Modules to Manipulate Files
Managing SELinux Properties
Using Jinja2 Templates
The following RHCE exam objectives are covered in this chapter:
Use Ansible modules for system administration tasks that work with:
File contents
Use advanced Ansible features
Create and use templates to create customized configuration files
“Do I Know This Already?” Quiz
The “Do I Know This Already?” quiz allows you to assess whether you should read this entire chapter thoroughly or jump to the “Exam Preparation Tasks” section. If you are in doubt about your answers to these questions or your own assessment of your knowledge of the topics, read the entire chapter. Table 8-1 lists the major headings in this chapter and their corresponding “Do I Know This Already?” quiz questions. You can find the answers in Appendix A, “Answers to the ‘Do I Know This Already?’ Quizzes and Review Questions.”
Table 8-1 “Do I Know This Already?” Section-to-Question Mapping
Foundation Topics Section |
Questions |
|---|---|
Using Modules to Manipulate Files |
1–6 |
Managing SELinux Properties |
7, 8 |
Using Jinja2 Templates |
9, 10 |
1. Which module should you use to check the current permission mode on a file?
stat
file
permissions
acl
2. Which module should you use to replace a line of text in a configuration file with another line of text?
copy
regex
lineinfile
blockinfile
3. Which of the following shows correct syntax for a when statement that runs a task only if the permission mode as discovered by the stat module and registered to the st variable is not set to 0640?
st.mode != '0640'
st.stat.mode != 0640
st.stat.mode != '0640'
st.mode != 0640
4. Which of the following lines shows correct use of the lineinfile module to find a line that begins with PermitRootLogin based on a regular expression?
line: "PermitRootLogin"
line: "^PermitRootLogin"
regexp: "PermitRootLogin"
regexp: "^PermitRootLogin"
5. Which of the following is not a common task that the file module can do?
Remove files
Copy a line of text into a file
Create links
Set permissions
6. Which module can you use to copy a file from a managed node to the control node?
copy
file
sync
fetch
7. Different modules can be used when working with SELinux. Which of the following modules should you avoid?
file
sefcontext
command
selinux
8. After you set an SELinux context, the Linux restorecon command must be executed. How would you do this?
Use the command module to run the restorecon command.
Use the restorecon module.
Use the selinux module.
No further action is needed; this is done automatically when using the appropriate SELinux module.
9. What do you need to transform the contents of a variable to the JSON format?
The lineinfile module
A Jinja2 template
A filter
The copy module
10. What should you use to process host-specific facts from a template?
The hostvars macro
The hostvars magic variable
The hostvars module
The hostvars filter
