mrlesmithjr / ansible-mdadm

60 stars 42 forks source link

Duplicate entries can be created in mdadm.conf when pre-existing mdraid devices are 'imported' #28

Closed dougszumski closed 1 year ago

dougszumski commented 1 year ago

Describe the bug

If ansible-mdadm is used to manage mdraid devices created via another means, duplicate entries may be created in mdadm.conf. In the worst case, this may prevent a machine booting.

To Reproduce

As an example:

  1. Install Centos using Anaconda. During the installation configure an mdraid device for use as the rootfs.
  2. Anaconda creates mdadm.conf. Everything is fine so far. For example:
# mdadm.conf written out by anaconda
    MAILADDR root
    AUTO +imsm +1.x -all

    ARRAY /dev/md/pv00 level=raid1 num-devices=2 UUID=982e5d2d:b145f191:52abcf49:5ebffa20
    ARRAY /dev/md/boot level=raid1 num-devices=2 UUID=ec253f6b:45ef42ae:4182ed28:0cd28b9b
    ARRAY /dev/md/boot_efi level=raid1 num-devices=2 UUID=26460904:051f0259:cfc9daf0:9e0898eb
    ARRAY /dev/md124 level=raid1 num-devices=2 UUID=1ab96384:06a092f2:910f1eda:2255e814
  1. Now add, for example /dev/md124 to ansible-mdadm configuration and run the role.
  2. ansible-mdadm writes the output from mdadm --detail --scan to mdadm.conf. The regex doesn't match the existing entries, resulting in two entries per device. For example:
    # mdadm.conf written out by anaconda
    MAILADDR root
    AUTO +imsm +1.x -all

    ARRAY /dev/md/pv00 level=raid1 num-devices=2 UUID=982e5d2d:b145f191:52abcf49:5ebffa20
    ARRAY /dev/md/boot level=raid1 num-devices=2 UUID=ec253f6b:45ef42ae:4182ed28:0cd28b9b
    ARRAY /dev/md/boot_efi level=raid1 num-devices=2 UUID=26460904:051f0259:cfc9daf0:9e0898eb
    ARRAY /dev/md124 level=raid1 num-devices=2 UUID=1ab96384:06a092f2:910f1eda:2255e814

        # These added by ansible-mdadm:
    ARRAY /dev/md/pv00 metadata=1.2 name=localhost.localdomain:pv00 UUID=982e5d2d:b145f191:52abcf49:5ebffa20
    ARRAY /dev/md/boot metadata=1.2 name=localhost.localdomain:boot UUID=ec253f6b:45ef42ae:4182ed28:0cd28b9b
    ARRAY /dev/md/boot_efi metadata=1.0 name=localhost.localdomain:boot_efi UUID=26460904:051f0259:cfc9daf0:9e0898eb
    ARRAY /dev/md124 metadata=1.2 name=124 UUID=1ab96384:06a092f2:910f1eda:2255e814
  1. Server may no longer boot due to duplicate entries.

Expected behaviour

  1. No duplicate entries are created in mdadm.conf
  2. For each mdraid device, if an entry already exists in mdadm.conf, it should be replaced using the format from ansible-mdadm.

I'm happy to submit a patch if we agree on the expected behaviour. It would be easy to match by UUID, rather than the whole ARRAY line. However, it could have side effects (removing level, num-devices from existing entries). Perhaps we should fail if this scenario happens, and prompt the user to take manual, remedial action instead?

Many thanks for your excellent work by-the-way.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

pavlozt commented 1 year ago

Unpleasant story. You may end up with a system that won't boot at all.

@mrlesmithjr , please, reopen