ansible-lockdown / RHEL7-STIG

Ansible role for Red Hat 7 STIG Baseline
MIT License
282 stars 144 forks source link

GRUB 2 config handler fails when /boot/grub2/user.cfg does not exist #440

Closed layluke closed 10 months ago

layluke commented 10 months ago

Describe the Issue When Flushing Handlers The following errors are encountered:

When /boot/grub2/user.cfg does not exist {{ rhel7stig_grub2_user_cfg }} does not get registered and "confirm grub2 user cfg" and "make grub2 config" tasks fail, causing the rest of the handlers not to run.

Expected Behavior The tasks mentioned should be able to handle the {{ rhel7stig_grub2_user_cfg }} not being registered

Actual Behavior The tasks mentioned fail with the following errors:

RUNNING HANDLER [RHEL7-STIG : copy grub2 config to BIOS/UEFI to satisfy benchmark] *** fatal: [rhel7-stig-r3v11-gui-test]: FAILED! => {"msg": "The conditional check 'rhel7stig_grub2_user_cfg.stat.exists' failed. The error was: error while evaluating conditional (rhel7stig_grub2_user_cfg.stat.exists): 'rhel7stig_grub2_user_cfg' is undefined\n\nThe error appears to be in '/runner/collections/roles/RHEL7-STIG/handlers/main.yml': line 34, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: copy grub2 config to BIOS/UEFI to satisfy benchmark\n ^ here\n"}

RUNNING HANDLER [RHEL7-STIG : make grub2 config] ***** fatal: [rhel7-stig-r3v11-gui-test]: FAILED! => {"msg": "The conditional check 'rhel7stig_grub2_user_cfg.stat.exists exists' failed. The error was: template error while templating string: expected token 'end of statement block', got 'exists'. String: {% if rhel7stig_grub2_user_cfg.stat.exists exists %} True {% else %} False {% endif %}\n\nThe error appears to be in '/runner/collections/roles/RHEL7-STIG/handlers/main.yml': line 27, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: make grub2 config\n ^ here\n"}

Control(s) Affected All controls that rely on the Grub handlers and everything after that

Environment (please complete the following information):

Additional Notes N/A

Possible Solution In the conditionals that checks to see if rhel7stig_grub2_user_cfg.stat.exists is true, add an and statement to check to see if is also defined.

Submitting a PR with this change

layluke commented 10 months ago

PR: https://github.com/ansible-lockdown/RHEL7-STIG/pull/441