Red Hat Certified Engineer RHCE · Free Practice Question Medium
Question 18
You are managing a role that installs security patches but want to ensure that the patches are only applied during a maintenance window. How would you use Ansible's scheduling features or cron within a role to ensure that patches are installed at the specified time?
-
A
Applying Patches During a Maintenance Window Using Cron in a Role
In the role'stasks/main.yml, schedule patch installation using cron:- - name: Schedule security patch installation
- ansible.builtin.cron:
- name: "Security Patching"
- minute: "0"
- hour: "2"
- job: "/usr/bin/ansible-playbook /path/to/patch_playbook.yml"
- user: root
This ensures patches are applied during a specified maintenance window (e.g., 2 AM).
-
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 solution demonstrates how to use Ansible's cron module to schedule security patch installations during a specified maintenance window. In this example, the cron module is used within the role to schedule the execution of a playbook (patch_playbook.yml) at a specific time. The cron job is set to run at 2 AM by specifying the minute and hour (minute: "0" and hour: "2"), ensuring that the patches are applied during the desired maintenance window. The job field specifies the command to run, which is the Ansible playbook that installs the patches. By using this approach, you can automate patching during off-peak hours, ensuring minimal disruption.
Line-by-Line Explanation
- name: Schedule security patch installationThis task is named "Schedule security patch installation," indicating that it is responsible for scheduling the patch installation using cron.
ansible.builtin.cron:This uses the
cronmodule to create or manage cron jobs on the target systems.
name: "Security Patching"Specifies a descriptive name for the cron job. This helps to identify the job in the system's crontab.
minute: "0"Specifies that the cron job will run at minute
0(i.e., at the start of the hour).
hour: "2"Specifies that the cron job will run at hour
2, which corresponds to 2 AM. This ensures that the patch installation occurs during the designated maintenance window.
job: "/usr/bin/ansible-playbook /path/to/patch_playbook.yml"Defines the command to be executed by cron. In this case, it runs the Ansible playbook
patch_playbook.ymlto apply the security patches.
user: rootSpecifies that the cron job should run as the
rootuser, ensuring that the necessary permissions are available for patch installation.
By using Ansible's cron module, this approach automates the scheduling of security patch installations during a specified maintenance window, ensuring that patches are applied without manual intervention and at an optimal time.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
