|
10 | 10 | tags: |
11 | 11 | - reset-bls-entries |
12 | 12 | tasks: |
13 | | - - name: Get machine ID |
14 | | - ansible.builtin.command: cat /etc/machine-id |
15 | | - register: machine_id |
16 | | - check_mode: false |
| 13 | + - name: Reset BLS entries on RedHat-based systems |
| 14 | + when: ansible_facts.os_family == 'RedHat' |
| 15 | + block: |
| 16 | + - name: Get machine ID |
| 17 | + ansible.builtin.command: cat /etc/machine-id |
| 18 | + register: machine_id |
| 19 | + check_mode: false |
17 | 20 |
|
18 | | - - name: Find entries with wrong machine ID |
19 | | - ansible.builtin.find: |
20 | | - paths: /boot/loader/entries |
21 | | - patterns: "*.conf" |
22 | | - register: bls_entries |
23 | | - check_mode: false |
| 21 | + - name: Find entries with wrong machine ID |
| 22 | + ansible.builtin.find: |
| 23 | + paths: /boot/loader/entries |
| 24 | + patterns: "*.conf" |
| 25 | + register: bls_entries |
| 26 | + check_mode: false |
24 | 27 |
|
25 | | - # We set force to false to avoid replacing an existing BLS entry with the |
26 | | - # correct machine ID. |
27 | | - - name: Rename entries with wrong machine ID |
28 | | - ansible.builtin.copy: |
29 | | - src: /boot/loader/entries/{{ item }} |
30 | | - dest: /boot/loader/entries/{{ item | ansible.builtin.regex_replace('^[a-f0-9]*', machine_id.stdout) }} |
31 | | - force: false |
32 | | - remote_src: true |
33 | | - with_items: "{{ bls_entries.files | map(attribute='path') | reject('search', machine_id.stdout) | map('basename') }}" |
| 28 | + # We set force to false to avoid replacing an existing BLS entry with the |
| 29 | + # correct machine ID. |
| 30 | + - name: Rename entries with wrong machine ID |
| 31 | + ansible.builtin.copy: |
| 32 | + src: /boot/loader/entries/{{ item }} |
| 33 | + dest: /boot/loader/entries/{{ item | ansible.builtin.regex_replace('^[a-f0-9]*', machine_id.stdout) }} |
| 34 | + force: false |
| 35 | + remote_src: true |
| 36 | + with_items: "{{ bls_entries.files | map(attribute='path') | reject('search', machine_id.stdout) | map('basename') }}" |
34 | 37 |
|
35 | | - - name: Remove entries with wrong machine ID |
36 | | - ansible.builtin.file: |
37 | | - path: /boot/loader/entries/{{ item }} |
38 | | - state: absent |
39 | | - with_items: "{{ bls_entries.files | map(attribute='path') | reject('search', machine_id.stdout) | map('basename') }}" |
| 38 | + - name: Remove entries with wrong machine ID |
| 39 | + ansible.builtin.file: |
| 40 | + path: /boot/loader/entries/{{ item }} |
| 41 | + state: absent |
| 42 | + with_items: "{{ bls_entries.files | map(attribute='path') | reject('search', machine_id.stdout) | map('basename') }}" |
0 commit comments