Red Hat Certified Engineer RHCE · Free Practice Question Medium

Question 13

You are asked to write a playbook that configures a web server to serve a static website. How would you use Ansible to ensure that the web server’s document root is configured, a sample HTML file is deployed, and the nginx service is started and enabled?

  • A

    This is a performance based question and not multiple choice.  Therefore the answer is in #1.  If you require additional explanation, please ask your question in the Q&A section.

  • B

    Configuring a Web Server to Serve a Static Website
    To configure the document root, deploy an HTML file, and start nginx:

    This sets up a static website and ensures nginx is running.

Reveal correct answer

Correct answer: B

B.

This playbook configures a web server to host a static website by performing three tasks. First, it creates a document root directory for storing the website files. Second, it deploys a sample HTML file to this directory to serve as the website's homepage. Finally, it ensures the nginx service is installed, started, and enabled at boot. This setup guarantees that the static website is accessible and automatically starts with the server.

Line-by-Line Explanation:

  1. Define Target Hosts:

    • Specifies that the playbook will run on all managed nodes listed in the inventory.

  2. Create Document Root Directory:

    • Creates the /var/www/html directory, which will serve as the document root for the static website.

    • The state: directory ensures the specified path exists as a directory.

  3. Deploy Sample HTML File:

    • Copies a sample HTML file (index.html) from the local system to the document root directory on the managed node.

    • The src parameter specifies the file's source location, while dest specifies the destination location.

  4. Start and Enable nginx:

    • Ensures the nginx service is started and enabled to run at boot.

    • The state: started parameter ensures the service is running, while enabled: yes ensures it starts automatically after a reboot.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need