From d2dadb65f7f7413323b5561c1f9415e0c2e641e9 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Tue, 23 Jul 2024 07:45:50 -0600 Subject: [PATCH] feat: write storage role fingerprint to /etc/fstab Feature: Write storage role fingerprint to /etc/fstab Reason: This will allow us to track usage of the storage role on managed nodes. Result: Storage role usage on managed nodes can be tracked. Signed-off-by: Rich Megginson --- tasks/main-blivet.yml | 18 ++++++++++++++++++ tests/test-verify-volume-fstab.yml | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/tasks/main-blivet.yml b/tasks/main-blivet.yml index f73be000..d1c3a35d 100644 --- a/tasks/main-blivet.yml +++ b/tasks/main-blivet.yml @@ -102,6 +102,24 @@ - storage_udevadm_trigger | d(false) - blivet_output is changed + - name: Check if /etc/fstab is present + stat: + path: /etc/fstab + register: __storage_fstab + + - name: Add fingerprint to /etc/fstab if present + lineinfile: + insertbefore: "^#" + firstmatch: true + line: "{{ __str }}" + regexp: "{{ __str }}" + path: /etc/fstab + state: present + vars: + __str: "# system_role:storage" + when: + - __storage_fstab.stat.exists + - blivet_output is changed rescue: - name: Failed message fail: diff --git a/tests/test-verify-volume-fstab.yml b/tests/test-verify-volume-fstab.yml index f4414e2c..5c6a12f4 100644 --- a/tests/test-verify-volume-fstab.yml +++ b/tests/test-verify-volume-fstab.yml @@ -68,6 +68,12 @@ - "'mount_options' in storage_test_volume" - "'mount_point' in storage_test_volume" +- name: Verify fingerprint + assert: + that: __fingerprint in storage_test_fstab.stdout + vars: + __fingerprint: "system_role:storage" + - name: Clean up variables set_fact: storage_test_fstab_id_matches: null