|
80 | 80 |
|
81 | 81 | - name: Check current GRUB_CMDLINE_LINUX_DEFAULT
|
82 | 82 | become: yes
|
83 |
| - shell: grep '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub || echo 'GRUB_CMDLINE_LINUX_DEFAULT=""' |
| 83 | + shell: | |
| 84 | + if grep -q '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub; then |
| 85 | + grep '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub | sed 's/^GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"$/\1/' |
| 86 | + else |
| 87 | + echo "" |
| 88 | + fi |
84 | 89 | register: current_grub_cmdline
|
85 | 90 | changed_when: false
|
86 | 91 | when: stage2_nix
|
|
92 | 97 | changed_when: false
|
93 | 98 | when: stage2_nix
|
94 | 99 |
|
| 100 | +- name: Prepare GRUB cmdline with coredump_filter |
| 101 | + set_fact: |
| 102 | + new_grub_cmdline: "{{ (current_grub_cmdline.stdout | regex_replace('coredump_filter=[0-9]+', '') | trim + ' coredump_filter=49') | trim }}" |
| 103 | + when: stage2_nix |
| 104 | + |
95 | 105 | - name: Update GRUB configuration for coredump_filter in main grub file
|
96 | 106 | become: yes
|
97 | 107 | lineinfile:
|
98 | 108 | path: /etc/default/grub
|
99 | 109 | regexp: '^GRUB_CMDLINE_LINUX_DEFAULT='
|
100 |
| - line: 'GRUB_CMDLINE_LINUX_DEFAULT="{{ current_grub_cmdline.stdout | regex_replace("^GRUB_CMDLINE_LINUX_DEFAULT=\"(.*)\"$", "\\1") | regex_replace("coredump_filter=[0-9]+", "") | trim }} coredump_filter=49"' |
101 |
| - backrefs: no |
| 110 | + line: 'GRUB_CMDLINE_LINUX_DEFAULT="{{ new_grub_cmdline }}"' |
| 111 | + create: yes |
102 | 112 | when:
|
103 | 113 | - stage2_nix
|
104 | 114 | - grub_d_files.stdout == ""
|
105 | 115 | register: grub_main_updated
|
106 | 116 |
|
107 | 117 | - name: Update GRUB configuration for coredump_filter in grub.d files
|
108 | 118 | become: yes
|
109 |
| - lineinfile: |
110 |
| - path: "{{ item }}" |
111 |
| - regexp: '^GRUB_CMDLINE_LINUX_DEFAULT=' |
112 |
| - line: 'GRUB_CMDLINE_LINUX_DEFAULT="{{ lookup("pipe", "grep \"^GRUB_CMDLINE_LINUX_DEFAULT=\" " + item + " | sed \"s/^GRUB_CMDLINE_LINUX_DEFAULT=\\\"\\(.*\\)\\\"$/\\1/\" | sed \"s/coredump_filter=[0-9]*//g\"") | trim }} coredump_filter=49"' |
113 |
| - backrefs: no |
114 |
| - with_items: "{{ grub_d_files.stdout_lines }}" |
| 119 | + shell: | |
| 120 | + for file in {{ grub_d_files.stdout }}; do |
| 121 | + current=$(grep '^GRUB_CMDLINE_LINUX_DEFAULT=' "$file" | sed 's/^GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"$/\1/') |
| 122 | + new=$(echo "$current" | sed 's/coredump_filter=[0-9]*//g') |
| 123 | + new="${new} coredump_filter=49" |
| 124 | + sed -i "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"${new}\"/" "$file" |
| 125 | + done |
115 | 126 | when:
|
116 | 127 | - stage2_nix
|
117 | 128 | - grub_d_files.stdout != ""
|
|
122 | 133 | command: update-grub
|
123 | 134 | when:
|
124 | 135 | - stage2_nix
|
125 |
| - - grub_main_updated.changed or grub_d_updated.changed |
| 136 | + - (grub_main_updated is defined and grub_main_updated.changed) or (grub_d_updated is defined and grub_d_updated.changed) |
126 | 137 |
|
127 | 138 | - name: Install gdb for debugging
|
128 | 139 | become: yes
|
|
0 commit comments