Home > Articles

Deploying Files

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 is from the book

This chapter is from the book

This chapter covers the following subjects:

  • squ.jpg Using Modules to Manipulate Files

  • squ.jpg Managing SELinux Properties

  • squ.jpg Using Jinja2 Templates

The following RHCE exam objectives are covered in this chapter:

  • squ.jpg Use Ansible modules for system administration tasks that work with:

    • squ.jpg File contents

  • squ.jpg Use advanced Ansible features

    • squ.jpg 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?

  1. stat

  2. file

  3. permissions

  4. acl

2. Which module should you use to replace a line of text in a configuration file with another line of text?

  1. copy

  2. regex

  3. lineinfile

  4. 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?

  1. st.mode != '0640'

  2. st.stat.mode != 0640

  3. st.stat.mode != '0640'

  4. 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?

  1. line: "PermitRootLogin"

  2. line: "^PermitRootLogin"

  3. regexp: "PermitRootLogin"

  4. regexp: "^PermitRootLogin"

5. Which of the following is not a common task that the file module can do?

  1. Remove files

  2. Copy a line of text into a file

  3. Create links

  4. Set permissions

6. Which module can you use to copy a file from a managed node to the control node?

  1. copy

  2. file

  3. sync

  4. fetch

7. Different modules can be used when working with SELinux. Which of the following modules should you avoid?

  1. file

  2. sefcontext

  3. command

  4. selinux

8. After you set an SELinux context, the Linux restorecon command must be executed. How would you do this?

  1. Use the command module to run the restorecon command.

  2. Use the restorecon module.

  3. Use the selinux module.

  4. 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?

  1. The lineinfile module

  2. A Jinja2 template

  3. A filter

  4. The copy module

10. What should you use to process host-specific facts from a template?

  1. The hostvars macro

  2. The hostvars magic variable

  3. The hostvars module

  4. The hostvars filter

Foundation Topics

Pearson IT Certification Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Pearson IT Certification and its family of brands. I can unsubscribe at any time.