main.yml 3.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
- name: "Install parted"
  package:
    name: parted
    state: present
    use: '{{ disk_package_use }}'
  when: disk_additional_disks
  tags: ['disk', 'pkgs']

- name: "Install additional fs progs"
  package:
    name: "{{ item }}"
    state: present
  with_items: "{{ additional_fs_utils|default([]) }}"
  when: additional_fs_utils is defined
  tags: ['disk', 'pkgs']

- name: "Get disk alignment for disks"
  shell: |
    if
      [[ -e /sys/block/{{ item.disk | basename }}/queue/optimal_io_size && -e /sys/block/{{ item.disk | basename }}/alignment_offset && -e /sys/block/{{ item.disk | basename }}/queue/physical_block_size ]];
    then
      echo $[$(( ($(cat /sys/block/{{ item.disk | basename }}/queue/optimal_io_size) + $(cat /sys/block/{{ item.disk | basename }}/alignment_offset)) / $(cat /sys/block/{{ item.disk | basename }}/queue/physical_block_size) )) | 2048];
    else
      echo 2048;
    fi
  args:
    creates: '{{ item.part | default(item.disk + "1") }}'
    executable: '/bin/bash'
  with_items: '{{ disk_additional_disks }}'
  register: disk_offset
  tags: ['disk']

- name: "Partition additional disks"
  shell: |
    if
        [ -b {{ item.disk }} ]
    then
        [ -b {{ item.part | default(item.disk + "1") }} ] || parted -a optimal --script "{{ item.disk }}" mklabel gpt mkpart primary {{ disk_offset.stdout|default("2048") }}s 100% && sleep 5 && partprobe {{ item.disk }}; sleep 5
    fi
  args:
    creates: '{{ item.part | default(item.disk + "1") }}'
    executable: '/bin/bash'
  with_items: '{{ disk_additional_disks }}'
  tags: ['disk']

- name: "Create filesystem on the first partition"
  filesystem:
    dev: '{{ item.part | default(item.disk + "1") }}'
    force: '{{ item.force|d(omit) }}'
    fstype: '{{ item.fstype }}'
    opts: '{{ item.fsopts|d(omit) }}'
  with_items: '{{ disk_additional_disks }}'
  tags: ['disk']

- name: "Disable periodic fsck on ext3 or ext4 formatted disks"
  shell: tune2fs -c0 -i0 {{ item.part | default(item.disk + "1") }}
  with_items: '{{ disk_additional_disks }}'
  when: "disk_additional_disks and ( item.fstype == 'ext4' or item.fstype == 'ext3' ) and item.disable_periodic_fsck|default(false)|bool"
  tags: ['disk']

- name: "Ensure the mount directory exists"
  file:
    path: '{{ item.mount }}'
    owner: '{{ item.user | default("root") }}'
    group: '{{ item.group | default("root") }}'
    state: directory
  with_items: '{{ disk_additional_disks }}'
  tags: ['disk']

- name: "Get UUID for partition"
  command: blkid -s UUID -o value {{ item.part | default(item.disk + "1") }}
  register: disk_blkid
  with_items: '{{ disk_additional_disks }}'
  changed_when: False
  tags: ['disk']

- name: "Mount additional disk"
  mount:
    name: '{{ item.0.mount }}'
    fstype: '{{ item.0.fstype }}'
    opts: '{{ item.0.mount_options|d(omit) }}'
    passno: '0'
    src: 'UUID={{ item.1.stdout }}'
    state: '{{ item.0.mount_state|d("mounted") }}'
  with_together:
    - '{{ disk_additional_disks }}'
    - '{{ disk_blkid.results }}'
  tags: ['disk']

- name: "Ensure the permissions are set correctly"
  file:
    path: '{{ item.mount }}'
    owner: '{{ item.user | default("root") }}'
    group: '{{ item.group | default("root") }}'
    state: directory
  with_items: '{{ disk_additional_disks }}'
  tags: ['disk']