---
- name: register filesystem
  shell: cat /etc/fstab | grep -o {{ item.filesystem }}
  changed_when: false
  with_items: "{{ mkinitcpio }}"
  register: mkinitcpio_fstab
  tags: mkinitcpio,fstab,dm-crypt

- block:
  - name: setup filesystem modules
    set_fact:
      mkinitcpio_modules: "{{ mkinitcpio_modules }} + {{ item.item.modules }}"
    with_items: "{{ mkinitcpio_fstab.results }}"

  - name: install filesystem deps
    pacman:
      name: "{{ item.item.utils | default(omit) }}"
      update_cache: true
    with_items: "{{ mkinitcpio_fstab.results }}"

  when: item.stdout.find(item.item.filesystem) != -1
  tags: mkinitcpio,fstab,dm-crypt

- name: setup disk encryption
  set_fact:
    mkinitcpio_hooks: "{{ mkinitcpio_hooks }} + ['lvm2', 'encrypt']"
    mkinitcpio_files: "{{ mkinitcpio_files }} + ['/crypto_keyfile.bin']"
  when: boot_encryption.enabled
  tags: mkinitcpio,fstab,dm-crypt

- name: setup mkinitcpio
  template:
    src: mkinitcpio.conf.j2
    dest: /etc/mkinitcpio.conf
    mode: 0644
  notify: mkinitcpio
  tags: mkinitcpio,fstab,dm-crypt

---
- name: register filesystem
  shell: cat /etc/fstab | grep -o {{ item.filesystem }}
  changed_when: false
  failed_when: mkinitcpio_fstab.rc > 1
  with_items: "{{ mkinitcpio }}"
  register: mkinitcpio_fstab
  tags: mkinitcpio,fstab,dm-crypt

- block:
  - name: setup filesystem modules
    set_fact:
      mkinitcpio_modules: "{{ mkinitcpio_modules }} + {{ item.item.modules }}"
    with_items: "{{ mkinitcpio_fstab.results }}"

  - name: install filesystem deps
    pacman:
      name: "{{ item.item.utils | default(omit) }}"
      update_cache: true
    with_items: "{{ mkinitcpio_fstab.results }}"

  when: item.stdout.find(item.item.filesystem) != -1
  tags: mkinitcpio,fstab,dm-crypt

- name: setup disk encryption
  set_fact:
    mkinitcpio_hooks: "{{ mkinitcpio_hooks }} + ['lvm2', 'encrypt']"
    mkinitcpio_files: "{{ mkinitcpio_files }} + ['/crypto_keyfile.bin']"
  when: boot_encryption.enabled
  tags: mkinitcpio,fstab,dm-crypt

- name: setup mkinitcpio
  template:
    src: mkinitcpio.conf.j2
    dest: /etc/mkinitcpio.conf
    mode: 0644
  notify: mkinitcpio
  tags: mkinitcpio,fstab,dm-crypt

Fix mkinitcpio role fail at register filesystems
Fix mkinitcpio role fail at register filesystems

The mknitcpio role would fail because grep uses a return value of 1
when no match is found. The fix increments this by one, so > 1 will
fail the task.
