mrlesmithjr / ansible-mdadm

60 stars 42 forks source link

cannot create more than 1 md device, found error in task #22

Closed as-ximi closed 2 years ago

as-ximi commented 2 years ago

Describe the bug cannot create more than 1 md device, found error in task

To Reproduce Steps to reproduce the behavior:

  1. md3 device created on host before
  2. adding md4 device into template
    mdadm_arrays:
    - name: 'md3'
    devices:
      - '/dev/sdc'
      - '/dev/sdd'
      - '/dev/sde'
      - '/dev/sdf'
    filesystem: 'ext4'
    level: '10'
    mountpoint: '/mnt/md3'
    state: 'present'
    - name: 'md4'
    devices:
      - '/dev/sdg'
      - '/dev/sdh'
      - '/dev/sdi'
      - '/dev/sdj'
    filesystem: 'ext4'
    level: '10'
    mountpoint: '/mnt/md4'
    state: 'present'
  3. playing you role and task no creating array:
    
    TASK [mrlesmithjr.mdadm : arrays | Checking Status Of Array(s)]

ok: [db] => (item={u'state': u'present', u'name': u'md3', u'level': u'10', u'mountpoint': u'/mnt/md3', u'filesystem': u'ext4', u'devices': [u'/dev/sdc', u'/dev/sdd', u'/dev/sde', u'/dev/sdf']}) => { ... "rc": 0, STDOUT:

md3 : active raid10 sdd[3] sdc[2] sda[0] sdb[1]

ok: [db] => (item={u'state': u'present', u'name': u'md4', u'level': u'10', u'mountpoint': u'/mnt/md4', u'filesystem': u'ext4', u'devices': [u'/dev/sdg', u'/dev/sdh', u'/dev/sdi', u'/dev/sdj']}) => { ... "rc": 1, MSG:

non-zero return code

4. See error

1) md4 device not found, RC=1

2) But task "Creating Array(s)" skipped creatinf md4 device

```bash
TASK [mrlesmithjr.mdadm : arrays | Creating Array(s)]

skipping: [db] => (item={u'state': u'present', u'name': u'md3', u'level': u'10', u'mountpoint': u'/mnt/md3', u'filesystem': u'ext4', u'devices': [u'/dev/sdc', u'/dev/sdd', u'/dev/sde', u'/dev/sdf']})  => {
    "skip_reason": "Conditional result was False"

skipping: [db1] => (item={u'state': u'present', u'name': u'md4', u'level': u'10', u'mountpoint': u'/mnt/md4', u'filesystem': u'ext4', u'devices': [u'/dev/sdg', u'/dev/sdh', u'/dev/sdi', u'/dev/sdj']})  => {
    "skip_reason": "Conditional result was False"

Error found into file tasks/arrays.yml It was

# Creating raid arrays
# We pass yes in order to accept any questions prompted for yes|no
- name: arrays | Creating Array(s)
  shell: "yes | mdadm --create /dev/{{ item.name }} --level={{ item.level }} --raid-devices={{ item.devices|count }} {{ item.devices| join (' ') }}"
  register: "array_created"
  with_items: '{{ mdadm_arrays }}'
  when: >
        item.state|lower == "present" and
        array_check.results[0].rc != 0

Error found in line " array_check.results[0].rc != 0" for result index

FIX file tasks/arrays.yml

# Creating raid arrays
# We pass yes in order to accept any questions prompted for yes|no
- name: arrays | Creating Array(s)
  shell: "yes | mdadm --create /dev/{{ item.name }} --level={{ item.level }} --raid-devices={{ item.devices|count }} {{ item.devices| join (' ') }}"
  register: "array_created"
#  with_items: '{{ mdadm_arrays }}'
  loop: "{{ mdadm_arrays }}"
  loop_control:
    index_var: index
  when: >
        item.state|lower == "present" and
        array_check.results[index].rc != 0

I am applying index of array mdadm_arrays for array_check.results.RC

Playing after FIX

TASK [mrlesmithjr.mdadm : arrays | Creating Array(s)] *******************************************************************
skipping: [db] => (item={u'state': u'present', u'name': u'md3', u'level': u'10', u'mountpoint': u'/mnt/md3', u'filesystem': u'ext4', u'devices': [u'/dev/sdc', u'/dev/sdd', u'/dev/sde', u'/dev/sdf']})
changed: [db] => (item={u'state': u'present', u'name': u'md4', u'level': u'10', u'mountpoint': u'/mnt/md4', u'filesystem': u'ext4', u'devices': [u'/dev/sdg', u'/dev/sdh', u'/dev/sdi', u'/dev/sdj']})

TASK [mrlesmithjr.mdadm : arrays | Updating Initramfs] ******************************************************************
changed: [db]

TASK [mrlesmithjr.mdadm : arrays | Capturing Array Details] *************************************************************
ok: [db]

TASK [mrlesmithjr.mdadm : arrays | Creating Array(s) Filesystem] ********************************************************
ok: [db] => (item={u'state': u'present', u'name': u'md3', u'level': u'10', u'mountpoint': u'/mnt/md3', u'filesystem': u'ext4', u'devices': [u'/dev/sdc', u'/dev/sdd', u'/dev/sde', u'/dev/sdf']})
changed: [db] => (item={u'state': u'present', u'name': u'md4', u'level': u'10', u'mountpoint': u'/mnt/md4', u'filesystem': u'ext4', u'devices': [u'/dev/sdg', u'/dev/sdh', u'/dev/sdi', u'/dev/sdj']})

TASK [mrlesmithjr.mdadm : arrays | Mounting Array(s)] *******************************************************************
ok: [db] => (item={u'state': u'present', u'name': u'md3', u'level': u'10', u'mountpoint': u'/mnt/md3', u'filesystem': u'ext4', u'devices': [u'/dev/sdc', u'/dev/sdd', u'/dev/sde', u'/dev/sdf']})
changed: [db] => (item={u'state': u'present', u'name': u'md4', u'level': u'10', u'mountpoint': u'/mnt/md4', u'filesystem': u'ext4', u'devices': [u'/dev/sdg', u'/dev/sdh', u'/dev/sdi', u'/dev/sdj']})

on host

# cat /proc/mdstat
Personalities : [raid10] [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4]
md4 : active raid10 sdj[3] sdi[2] sdh[1] sdg[0]
      15000268800 blocks super 1.2 512K chunks 2 near-copies [8/8] [UUUUUUUU]
      [>....................]  resync =  0.2% (44098944/15000268800) finish=1205.9min speed=206695K/sec
      bitmap: 112/112 pages [448KB], 65536KB chunk
mrlesmithjr commented 2 years ago

@markgoddard If you have spare cycles would you mind taking a look at this?

markgoddard commented 2 years ago

From what I can see, the suggested fix looks appropriate. @as-ximi are you able to create a PR?

as-ximi commented 2 years ago

From what I can see, the suggested fix looks appropriate. @as-ximi are you able to create a PR?

Yes, sure I'll do it a little later

CendioMartin commented 2 years ago

I think this would also be true when stopping and destroying arrays tasks/arrays.yml array_check.results[0].rc Is used in multiple places in arrays.yml

as-ximi commented 2 years ago

I think this would also be true when stopping and destroying arrays tasks/arrays.yml array_check.results[0].rc Is used in multiple places in arrays.yml

yes, for the rest of the tasks, you also need to use index in result i will check it within a week

stale[bot] commented 2 years 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.