Red Hat Certified Engineer RHCE · Free Practice Question Medium

Question 11

You are tasked with configuring a group of servers to act as web servers, with all necessary packages installed, the correct configuration files deployed, and the web service started. How would you create a playbook that ensures these servers are configured to the desired state?

  • A

    Configuring Web Servers to the Desired State
    To install packages, deploy config files, and start the web service:

    This configures the servers as web servers.

  • B

    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.

Reveal correct answer

Correct answer: A

A.

This playbook defines tasks to install the necessary packages, deploy the configuration file, and ensure that theThis Ansible playbook configures web servers by installing the necessary web server software, deploying configuration files, and ensuring the web service is running. The playbook performs three tasks in sequence: first, it installs the Nginx package using the package module; second, it deploys the Nginx configuration file to the target servers using the copy module; and third, it ensures the Nginx service is running and enabled to start at boot using the service module. By executing these tasks, the playbook ensures the web servers are configured to the desired state, with the necessary packages, configurations, and services in place.


Line-by-Line Explanation

  1. - hosts: web_servers

    • Specifies that the tasks in this playbook will run on the group of hosts named web_servers.

  2. tasks:

    • This introduces the list of tasks to be executed on the target hosts.

  3. - name: Install necessary packages

    • This task is named "Install necessary packages," which installs the required software package for the web server.

  4. ansible.builtin.package:

    • This uses the package module to install software packages on the managed nodes.

  5. name: nginx

    • Specifies the name of the package to be installed, in this case, nginx.

  6. state: present

    • Ensures that the nginx package is installed. If it is already present, no action will be taken.

  7. - name: Deploy configuration file

    • This task is responsible for deploying the configuration file for Nginx.

  8. ansible.builtin.copy:

    • Uses the copy module to copy a file from the local machine to the target machine.

  9. src: /path/to/nginx.conf

    • Specifies the source path of the Nginx configuration file on the local machine.

  10. dest: /etc/nginx/nginx.conf

    • Specifies the destination path where the configuration file will be copied on the target machine.

  11. - name: Ensure nginx is running

    • This task ensures that the Nginx service is started and running on the target web servers.

  12. ansible.builtin.service:

    • Uses the service module to manage system services on the target machines.

  13. name: nginx

    • Specifies the service name, in this case, nginx, which is the web server service.

  14. state: started

    • Ensures the Nginx service is started.

  15. enabled: yes

    • Ensures that the Nginx service is enabled to start automatically on system boot.

By following this structure, the playbook ensures that the web servers are correctly configured, with the required software, configuration files, and services running as expected. nginx web service is running on the designated web servers. By using the Ansible built-in modules for package installation, file copying, and service management, this playbook effectively configures the servers to act as web servers with the desired state.

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