forked from ComplianceAsCode/content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_ANSIBLE_grub2_bootloader_argument
45 lines (37 loc) · 1.4 KB
/
template_ANSIBLE_grub2_bootloader_argument
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# platform = multi_platform_rhel,multi_platform_fedora,multi_platform_ol,multi_platform_rhv
# reboot = true
# strategy = restrict
# complexity = medium
# disruption = low
{{% if product in ["rhel7", "ol7"] %}}
- name: check {{{ ARG_NAME }}} argument exists
command: grep 'GRUB_CMDLINE_LINUX.*{{{ ARG_NAME }}}=' /etc/default/grub
failed_when: False
register: argcheck
- name: replace existing {{{ ARG_NAME }}} argument
replace:
path: /etc/default/grub
regexp: '{{{ ARG_NAME }}}=\w+'
replace: '{{{ ARG_NAME_VALUE }}}'
when: argcheck.rc == 0
- name: add {{{ ARG_NAME }}} argument
replace:
path: /etc/default/grub
regexp: '(GRUB_CMDLINE_LINUX=.*)"'
replace: '\1 {{{ ARG_NAME_VALUE }}}"'
when: argcheck.rc != 0
- name: update bootloader menu
command: /sbin/grubby --update-kernel=ALL --args="{{{ ARG_NAME_VALUE }}}"
{{% else %}}
- name: get current kernel parameters
command: '/usr/bin/grub2-editenv - list'
register: kernelopts
changed_when: False
- name: Update the bootloader menu
command: /usr/bin/grub2-editenv - set "{{ item }} {{{ ARG_NAME_VALUE }}}"
with_items: "{{ kernelopts.stdout_lines | select('match', '^kernelopts.*') | list }}"
when:
- kernelopts.stdout_lines is defined
- kernelopts.stdout_lines | length > 0
- kernelopts.stdout | regex_search('^kernelopts=(?:.*\s)?{{{ ARG_NAME_VALUE }}}(?:\s.*)?$', multiline=True) is none
{{% endif %}}