7.3. Setting a timeout for the boot loader menu by using the bootloader RHEL system role
You can use the bootloader RHEL system role to configure a timeout for the GRUB2 boot loader menu in an automated fashion. This way you can efficiently update a period of time during which you can intervene and select a non-default boot entry for various purposes.
Prerequisites
- You have prepared the control node and the managed nodes.
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions for these nodes.
Procedure
Create a playbook file, for example,
~/playbook.yml, with the following content:--- - name: Configuration and management of GRUB2 boot loader hosts: managed-node-01.example.com tasks: - name: Update the boot loader timeout ansible.builtin.include_role: name: redhat.rhel_system_roles.bootloader vars: bootloader_timeout: 10The settings specified in the example playbook include the following:
bootloader_timeout: 10- Input an integer to control for how long the GRUB2 boot loader menu is displayed before booting the default entry.
For details about all variables used in the playbook, see the
/usr/share/ansible/roles/rhel-system-roles.bootloader/README.mdfile on the control node.Validate the playbook syntax:
$ ansible-playbook --syntax-check ~/playbook.ymlNote that this command only validates the syntax and does not protect against a wrong but valid configuration.
Run the playbook:
$ ansible-playbook ~/playbook.yml
Verification
Remotely restart your managed node:
# ansible managed-node-01.example.com -m ansible.builtin.reboot managed-node-01.example.com | CHANGED => { "changed": true, "elapsed": 21, "rebooted": true }On the managed node, observe the GRUB2 boot menu screen.
The highlighted entry will be executed automatically in 10sFor how long this boot menu is displayed before GRUB2 automatically uses the default entry.
Alternative: you can remotely query for the "timeout" settings in the
/boot/grub2/grub.cfgfile of your managed node:# ansible managed-node-01.example.com -m ansible.builtin.command -a "grep 'timeout' /boot/grub2/grub.cfg" managed-node-01.example.com | CHANGED | rc=0 >> if [ x$feature_timeout_style = xy ] ; then set timeout_style=menu set timeout=10 # Fallback normal timeout code in case the timeout_style feature is set timeout=10 if [ x$feature_timeout_style = xy ] ; then set timeout_style=menu set timeout=10 set orig_timeout_style=${timeout_style} set orig_timeout=${timeout} # timeout_style=menu + timeout=0 avoids the countdown code keypress check set timeout_style=menu set timeout=10 set timeout_style=hidden set timeout=10 if [ x$feature_timeout_style = xy ]; then if [ "${menu_show_once_timeout}" ]; then set timeout_style=menu set timeout=10 unset menu_show_once_timeout save_env menu_show_once_timeout