From 5dc1478c65ffb9ade3a90412efd619018eb375dd Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Mon, 4 Dec 2017 00:37:24 +0000 Subject: [PATCH] refactored --- defaults/main.yml | 13 +- tasks/base_profile.yml | 23 ++ tasks/crypt_profile.yml | 12 + tasks/efi_filesystem.yml | 6 + tasks/filesystems.yml | 16 ++ tasks/host_vars.yml | 16 +- tasks/main.yml | 25 +-- tasks/raid_profile.yml | 19 ++ tasks/scan.yml | 12 + tasks/swap_devices.yml | 11 + tasks/volumes.yml | 0 templates/filesystems.json.j2 | 8 + templates/hard_disks.json.j2 | 144 ------------ templates/hard_disks_base_profile.json.j2 | 22 ++ templates/hard_disks_scan.json.j2 | 8 + templates/hard_disks_set.json.j2 | 39 ++++ templates/swap_devices.json.j2 | 8 + vars/base_profiles/bios-gpt.yml | 29 +++ vars/base_profiles/bios-mbr.yml | 18 ++ vars/base_profiles/efi.yml | 33 +++ vars/crypt_profiles/dmcrypt-luks.yml | 11 + vars/crypt_profiles/none.yml | 5 + vars/main.yml | 257 ++++------------------ vars/raid_profiles/mirror.yml | 17 ++ vars/raid_profiles/single.yml | 7 + vars/raid_profiles/strip.yml | 17 ++ 26 files changed, 396 insertions(+), 380 deletions(-) create mode 100644 tasks/base_profile.yml create mode 100644 tasks/crypt_profile.yml create mode 100644 tasks/efi_filesystem.yml create mode 100644 tasks/filesystems.yml create mode 100644 tasks/raid_profile.yml create mode 100644 tasks/scan.yml create mode 100644 tasks/swap_devices.yml create mode 100644 tasks/volumes.yml create mode 100644 templates/filesystems.json.j2 delete mode 100644 templates/hard_disks.json.j2 create mode 100644 templates/hard_disks_base_profile.json.j2 create mode 100644 templates/hard_disks_scan.json.j2 create mode 100644 templates/hard_disks_set.json.j2 create mode 100644 templates/swap_devices.json.j2 create mode 100644 vars/base_profiles/bios-gpt.yml create mode 100644 vars/base_profiles/bios-mbr.yml create mode 100644 vars/base_profiles/efi.yml create mode 100644 vars/crypt_profiles/dmcrypt-luks.yml create mode 100644 vars/crypt_profiles/none.yml create mode 100644 vars/raid_profiles/mirror.yml create mode 100644 vars/raid_profiles/single.yml create mode 100644 vars/raid_profiles/strip.yml diff --git a/defaults/main.yml b/defaults/main.yml index dbb4865..6985c0c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1 +1,12 @@ -partitioning_profile_last_partition_end: -1MiB +partitioning_base_profile: bios-gpt +partitioning_raid_profile: auto +partitioning_crypt_profile: none + +hard_disks_scan: false + +last_partition_end: -1MiB + +primary_volume_group_name: "{{inventory_hostname_short}}-vg0" + +root_partition_default_size: 32G +swap_partition_default_size: 2G diff --git a/tasks/base_profile.yml b/tasks/base_profile.yml new file mode 100644 index 0000000..6b363d2 --- /dev/null +++ b/tasks/base_profile.yml @@ -0,0 +1,23 @@ +--- + +- name: load base profile vars + include_vars: + file: "base_profiles/{{partitioning_base_profile}}.yml" + name: _partitioning_base_profile + +- name: set base profile vars + set_fact: + debian_boot_packages: "{{ debian_boot_packages | union(_partitioning_base_profile.debian_boot_packages) }}" + +- name: set hard disks base profile + set_fact: + hard_disks: "{{lookup('template','hard_disks_base_profile.json.j2')}}" + +- name: set hard disks + set_fact: + hard_disks: "{{lookup('template','hard_disks_set.json.j2')}}" + +# - name: debug hard hard_disks +# debug: +# msg: +# hard_disks: "{{hard_disks}}" diff --git a/tasks/crypt_profile.yml b/tasks/crypt_profile.yml new file mode 100644 index 0000000..3beffc2 --- /dev/null +++ b/tasks/crypt_profile.yml @@ -0,0 +1,12 @@ +--- + +- name: load crypt profile vars + include_vars: + file: "crypt_profiles/{{partitioning_crypt_profile}}.yml" + name: _partitioning_crypt_profile + +- name: set crypt profile vars + set_fact: + dmcrypt_devices: "{{_partitioning_crypt_profile.dmcrypt_devices}}" + system_device: "{{_partitioning_crypt_profile.system_device}}" + debian_boot_packages: "{{ debian_boot_packages | union(_partitioning_crypt_profile.debian_boot_packages) }}" diff --git a/tasks/efi_filesystem.yml b/tasks/efi_filesystem.yml new file mode 100644 index 0000000..10d0f5a --- /dev/null +++ b/tasks/efi_filesystem.yml @@ -0,0 +1,6 @@ +--- + +- name: set efi file system + set_fact: + filesystems: "{{ filesystems | union(_efi_filesystems) }}" + when: partitioning_base_profile == 'efi' diff --git a/tasks/filesystems.yml b/tasks/filesystems.yml new file mode 100644 index 0000000..8c67635 --- /dev/null +++ b/tasks/filesystems.yml @@ -0,0 +1,16 @@ +--- + +- name: generate filesystem uuids + local_action: command uuid -v4 + with_items: "{{filesystems}}" + register: _filesystems_uuids + changed_when: false + +- name: set filesystems + set_fact: + filesystems: "{{lookup('template','filesystems.json.j2')}}" + +# - debug: +# msg: +# _filesystems_uuids: "{{_filesystems_uuids}}" +# filesystems: "{{filesystems}}" diff --git a/tasks/host_vars.yml b/tasks/host_vars.yml index 6f176a5..9c02a64 100644 --- a/tasks/host_vars.yml +++ b/tasks/host_vars.yml @@ -1,16 +1,16 @@ --- - name: host_vars directory - local_action: - file - path={{ playbook_dir }}/host_vars/{{inventory_hostname}} - state=directory + local_action: file + args: + path: "{{ playbook_dir }}/host_vars/{{inventory_hostname}}" + state: directory - name: host_vars file - local_action: - template - src=host_vars.yml.j2 - dest={{ playbook_dir }}/host_vars/{{inventory_hostname}}/{{_host_vars_filename}}.yml + local_action: template + args: + src: host_vars.yml.j2 + dest: "{{ playbook_dir }}/host_vars/{{inventory_hostname}}/{{_host_vars_filename}}.yml" - name: include host_vars include_vars: diff --git a/tasks/main.yml b/tasks/main.yml index 0351635..47968b1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,20 +1,17 @@ --- -- name: set filesystem uuid namespace - set_fact: - filesystem_uuid_namespace: "{{ lookup('pipe','uuid -v4') }}" +- import_tasks: scan.yml -#- name: hard_disks debug -# debug: -# msg: "{{hard_disks}}" -# when: hard_disks is defined +- import_tasks: base_profile.yml -- name: set hard_disks - set_fact: - hard_disks: "{{lookup('template','hard_disks.json.j2')}}" +- import_tasks: raid_profile.yml -#- name: _host_vars debug -# debug: -# msg: "{{_host_vars}}" +- import_tasks: crypt_profile.yml -- include: host_vars.yml +- import_tasks: efi_filesystem.yml + +- import_tasks: filesystems.yml + +- import_tasks: swap_devices.yml + +- import_tasks: host_vars.yml diff --git a/tasks/raid_profile.yml b/tasks/raid_profile.yml new file mode 100644 index 0000000..519bddc --- /dev/null +++ b/tasks/raid_profile.yml @@ -0,0 +1,19 @@ +--- + +- name: set raid profile to mdraid if more than one disk and to single if one + set_fact: + partitioning_raid_profile: "{{ ( hard_disks | length > 1 ) | ternary('mirror','single') }}" + when: partitioning_raid_profile == 'auto' + +- name: load raid profile vars + include_vars: + file: "raid_profiles/{{partitioning_raid_profile}}.yml" + name: _partitioning_raid_profile + +- name: set raid profile vars + set_fact: + mdraid_devices: "{{_partitioning_raid_profile.mdraid_devices}}" + boot_device: "{{_partitioning_raid_profile.boot_device}}" + rescue_device: "{{_partitioning_raid_profile.rescue_device}}" + system_device: "{{_partitioning_raid_profile.system_device}}" + debian_boot_packages: "{{ debian_boot_packages | union(_partitioning_raid_profile.debian_boot_packages) }}" diff --git a/tasks/scan.yml b/tasks/scan.yml new file mode 100644 index 0000000..6604d26 --- /dev/null +++ b/tasks/scan.yml @@ -0,0 +1,12 @@ +--- + +# - name: ansible_devices debug +# debug: +# msg: "{{ansible_devices}}" + +- name: scan hard disks + set_fact: + hard_disks: "{{lookup('template','hard_disks_scan.json.j2')}}" + when: + - not hard_disks is defined + - hard_disks_scan diff --git a/tasks/swap_devices.yml b/tasks/swap_devices.yml new file mode 100644 index 0000000..a84c4b1 --- /dev/null +++ b/tasks/swap_devices.yml @@ -0,0 +1,11 @@ +--- + +- name: generate swap device uuids + local_action: command uuid -v4 + with_items: "{{filesystems}}" + register: _swap_devices_uuids + changed_when: false + +- name: set filesystems + set_fact: + swap_devices: "{{lookup('template','swap_devices.json.j2')}}" diff --git a/tasks/volumes.yml b/tasks/volumes.yml new file mode 100644 index 0000000..e69de29 diff --git a/templates/filesystems.json.j2 b/templates/filesystems.json.j2 new file mode 100644 index 0000000..dcd67cd --- /dev/null +++ b/templates/filesystems.json.j2 @@ -0,0 +1,8 @@ +[ +{% for fs in filesystems %} +{% if not fs.uuid is defined and fs.fstype != 'vfat' %} +{% set fs = fs | combine({ 'uuid': _filesystems_uuids.results[loop.index0].stdout }) %} +{% endif %} +{{fs|to_json}}, +{% endfor %} +] diff --git a/templates/hard_disks.json.j2 b/templates/hard_disks.json.j2 deleted file mode 100644 index 06039da..0000000 --- a/templates/hard_disks.json.j2 +++ /dev/null @@ -1,144 +0,0 @@ -[ -{# -{% if not hard_disks is defined %} -{% for device in ansible_devices.keys() %} -{% set name = device %} -{% set device = '/dev/' + device %} -{% endif %} -#} -{% for hd in hard_disks %} -{% set first_device = (hard_disks | first) == hd %} -{% set name = hd.name %} -{% set device = hd.device %} -{ - "device": "{{device}}", - "name": "{{name}}", - "label_type": "{{ _label_type[partitioning_profile] }}", - "partitions": - [ - {% set partition_name_prefix = inventory_hostname_short + '-' + name %} - {% if partitioning_profile == "bios-mbr-dmcrypt-lvm" %} - { - "part_type": "primary", - "fs_type": "btrfs", - "start": "768MiB", - "end": "1GiB" - } - { - "part_type": "primary", - "fs_type": "btrfs", - "start": "1GiB", - "end": "2GiB" - } - { - "part_type": "primary", - "fs_type": "btrfs", - "start": "2GiB", - "end": "6GiB" - } - { - "part_type": "primary", - "start": "6GiB", - "end": "{{ partitioning_profile_last_partition_end }}" - } - {% endif %} - {% if partitioning_profile == "efi-dmcrypt-lvm" %} - { - "part_type": "ESP", - "start": "256MiB", - "end": "768MiB" - }, - { - "name": "select", - "start": "768MiB", - "end": "1GiB" - }, - { - "name": "{{partition_name_prefix}}-boot", - "typecode": "8300", - "start": "1GiB", - "end": "2GiB" - }, - { - "name": "{{partition_name_prefix}}-rescue", - "typecode": "8300", - "start": "2GiB", - "end": "6GiB" - }, - { - "name": "{{partition_name_prefix}}-crypt", - "typecode": "8300", - "start": "6GiB", - "end": "{{ partitioning_profile_last_partition_end }}" - } - {% endif %} - {% if partitioning_profile == "bios-gpt-mdraid-lvm" %} - { - "name": "bios_boot", - "start": "2MiB", - "end": "4MiB", - "flags": ["bios_grub"] - }, - {% if first_device %} - { - "name": "{{_select_partlabel}}", - "start": "768MiB", - "end": "1GiB" - }, - {% endif %} - { - "name": "{{partition_name_prefix}}-boot-md", - "start": "1GiB", - "end": "2GiB", - "mdraid": "boot" - }, - { - "name": "{{partition_name_prefix}}-rescue-md", - "start": "2GiB", - "end": "6GiB", - "mdraid": "rescue" - }, - { - "name": "{{partition_name_prefix}}-vg0-md", - "start": "6GiB", - "end": "{{ partitioning_profile_last_partition_end }}", - "mdraid": "vg0" - } - {% endif %} - {% if partitioning_profile == "efi-mdraid-lvm" %} - {% if first_device %} - { - "name": "{{_efi_partlabel}}", - "start": "256MiB", - "end": "768MiB", - "flags": ["boot"] - }, - { - "name": "{{_select_partlabel}}", - "start": "768MiB", - "end": "1GiB" - }, - {% endif %} - { - "name": "{{partition_name_prefix}}-boot-md", - "start": "1GiB", - "end": "2GiB", - "mdraid": "boot" - }, - { - "name": "{{partition_name_prefix}}-rescue-md", - "start": "2GiB", - "end": "6GiB", - "mdraid": "rescue" - }, - { - "name": "{{partition_name_prefix}}-vg0-md", - "start": "6GiB", - "end": "{{ partitioning_profile_last_partition_end }}", - "mdraid": "vg0" - } - {% endif %} - ] -}, -{% endfor %} -] diff --git a/templates/hard_disks_base_profile.json.j2 b/templates/hard_disks_base_profile.json.j2 new file mode 100644 index 0000000..77fd6fc --- /dev/null +++ b/templates/hard_disks_base_profile.json.j2 @@ -0,0 +1,22 @@ +[ +{% for hd in hard_disks %} +{% set first_device = (hard_disks | first) == hd %} +{ + "device": "{{hd.device}}", + "name": "{{hd.name}}", + "label_type": "{{ _partitioning_base_profile.label_type }}", + "partitions": [ + {% if first_device and _partitioning_base_profile.partitions_first_device is defined %} + {% for part in _partitioning_base_profile.partitions_first_device %} + {{part}}, + {% endfor %} + {% endif %} + {% if _partitioning_base_profile.partitions is defined %} + {% for part in _partitioning_base_profile.partitions %} + {{part}}, + {% endfor %} + {% endif %} #} + ] +}, +{% endfor %} +] diff --git a/templates/hard_disks_scan.json.j2 b/templates/hard_disks_scan.json.j2 new file mode 100644 index 0000000..ee9c5f9 --- /dev/null +++ b/templates/hard_disks_scan.json.j2 @@ -0,0 +1,8 @@ +[ +{% for device in ansible_devices.keys() %} +{ + "name": "{{device}}", + "device": "/dev/{{device}}", +}, +{% endfor %} +] diff --git a/templates/hard_disks_set.json.j2 b/templates/hard_disks_set.json.j2 new file mode 100644 index 0000000..5663567 --- /dev/null +++ b/templates/hard_disks_set.json.j2 @@ -0,0 +1,39 @@ +[ +{% for hd in hard_disks %} +{ + "name": "{{hd.name}}", + "device": "{{hd.device}}", + "label_type": "{{ hd.label_type }}", + "partitions": [ + {% for part in hd.partitions %} + + {% if hd.label_type == 'gpt' %} + + {% if not part.name is defined and ( part.prefix is defined or part.suffix is defined ) %} + {% set part = part | combine({ 'name': hd.name }) %} + + {% if part.prefix is defined %} + {% set part = part | combine({ 'name': part.prefix+part.name }) %} + {% endif %} + + {% if part.suffix is defined %} + {% set part = part | combine({ 'name': part.name+part.suffix }) %} + {% endif %} + + {% endif %} + + {% if part.name is defined and not part.device is defined %} + {% set part = part | combine({ 'device': '/dev/disk/by-partlabel/'+part.name }) %} + {% endif %} + + {% elif hd.label_type == 'msdos' and not part.device is defined %} + {% set part = part | combine({ 'device': hd.device+(loop.index|string) }) %} + {% endif %} + + {{part|to_json}}, + + {% endfor %} + ] +}, +{% endfor %} +] diff --git a/templates/swap_devices.json.j2 b/templates/swap_devices.json.j2 new file mode 100644 index 0000000..0dc8e4d --- /dev/null +++ b/templates/swap_devices.json.j2 @@ -0,0 +1,8 @@ +[ +{% for swap in swap_devices %} +{% if not swap.uuid is defined %} +{% set swap = swap | combine({ 'uuid': _swap_devices_uuids.results[loop.index0].stdout }) %} +{% endif %} +{{swap|to_json}}, +{% endfor %} +] diff --git a/vars/base_profiles/bios-gpt.yml b/vars/base_profiles/bios-gpt.yml new file mode 100644 index 0000000..19d5d81 --- /dev/null +++ b/vars/base_profiles/bios-gpt.yml @@ -0,0 +1,29 @@ +label_type: gpt + +partitions: + - name: bios_boot + start: 2MiB + end: 4MiB + flags: + - bios_grub + - prefix: "{{inventory_hostname_short}}-" + suffix: -boot + start: 512MiB + end: 1GiB + typecode: 8300 + usage: boot + - prefix: "{{inventory_hostname_short}}-" + suffix: -rescue + start: 1GiB + end: 2GiB + typecode: 8300 + usage: rescue + - prefix: "{{inventory_hostname_short}}-" + suffix: -system + start: 2GiB + end: "{{last_partition_end}}" + typecode: 8300 + usage: system + +debian_boot_packages: + - grub-pc diff --git a/vars/base_profiles/bios-mbr.yml b/vars/base_profiles/bios-mbr.yml new file mode 100644 index 0000000..b2d3246 --- /dev/null +++ b/vars/base_profiles/bios-mbr.yml @@ -0,0 +1,18 @@ +label_type: msdos + +partitions: + - type: primary + start: 512MiB + end: 1GiB + usage: boot + - type: primary + start: 1GiB + end: 2GiB + usage: rescue + - type: primary + start: 2GiB + end: "{{last_partition_end}}" + usage: system + +debian_boot_packages: + - grub-pc diff --git a/vars/base_profiles/efi.yml b/vars/base_profiles/efi.yml new file mode 100644 index 0000000..440563d --- /dev/null +++ b/vars/base_profiles/efi.yml @@ -0,0 +1,33 @@ +label_type: gpt + +partitions_first_device: + - name: "{{_efi_partlabel}}" + part_type: ESP + start: 4MiB + end: 512MiB + flags: + - boot + +partitions: + - prefix: "{{inventory_hostname_short}}-" + suffix: -boot + start: 512MiB + end: 1GiB + typecode: 8300 + usage: boot + - prefix: "{{inventory_hostname_short}}-" + suffix: -rescue + start: 1GiB + end: 2GiB + typecode: 8300 + usage: rescue + - prefix: "{{inventory_hostname_short}}-" + suffix: -system + start: 2GiB + end: "{{last_partition_end}}" + typecode: 8300 + usage: system + +debian_boot_packages: + - efibootmgr + - grub-efi-amd64 diff --git a/vars/crypt_profiles/dmcrypt-luks.yml b/vars/crypt_profiles/dmcrypt-luks.yml new file mode 100644 index 0000000..56c8b0a --- /dev/null +++ b/vars/crypt_profiles/dmcrypt-luks.yml @@ -0,0 +1,11 @@ +dmcrypt_devices: + - device: "{{ system_device }}" + name: "{{inventory_hostname}}-crypt0" + cipher: aes-xts-plain64 + hash: sha512 + key_size: 512 + +system_device: /dev/mapper/{{inventory_hostname}}-crypt0 + +debian_boot_packages: + - cryptsetup diff --git a/vars/crypt_profiles/none.yml b/vars/crypt_profiles/none.yml new file mode 100644 index 0000000..243b357 --- /dev/null +++ b/vars/crypt_profiles/none.yml @@ -0,0 +1,5 @@ +dmcrypt_devices: [] + +system_device: "{{ system_device }}" + +debian_boot_packages: [] diff --git a/vars/main.yml b/vars/main.yml index 497ffc4..1f186e1 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,222 +1,53 @@ -_host_vars_filename: partitioning -_host_vars_default: {} +_host_vars_filename: partitioning +_host_vars_default: {} _host_vars: - hard_disks: "{{ hard_disks }}" - mdraid_devices: "{{ _mdraid_devices[partitioning_profile] }}" - dmcrypt_devices: "{{ _dmcrypt_devices[partitioning_profile] }}" - volume_groups: "{{ _volume_groups[partitioning_profile] }}" - logical_volumes: "{{ _logical_volumes[partitioning_profile] }}" - filesystems: "{{ _filesystems[partitioning_profile] }}" - swap_devices: "{{ _swap_devices[partitioning_profile] }}" - debian_boot_packages: "{{ _debian_boot_packages[partitioning_profile] | union(_debian_boot_packages_all) }}" + hard_disks: "{{ hard_disks }}" + mdraid_devices: "{{ mdraid_devices }}" + dmcrypt_devices: "{{ dmcrypt_devices }}" + volume_groups: "{{ volume_groups }}" + logical_volumes: "{{ logical_volumes }}" + filesystems: "{{ filesystems }}" + swap_devices: "{{ swap_devices }}" + debian_boot_packages: "{{ debian_boot_packages }}" + +volume_groups: + - name: "{{primary_volume_group_name}}" + devices: + - "{{ system_device }}" + +logical_volumes: + - name: root + size: "{{root_partition_default_size}}" + - name: swap + size: "{{swap_partition_default_size}}" + +filesystems: + - device: "{{ boot_device }}" + mount_point: /boot + fstype: ext4 + - device: "{{ rescue_device }}" + mount_point: /rescue + fstype: btrfs + - device: /dev/{{primary_volume_group_name}}/root + mount_point: / + fstype: btrfs -_debian_boot_packages_all: +_efi_partlabel: "{{inventory_hostname_short}}-efi" +_efi_filesystems: + - device: /dev/disk/by-partlabel/{{_efi_partlabel}} + mount_point: /boot/efi + fstype: vfat + +swap_devices: + - device: /dev/{{primary_volume_group_name}}/swap + +debian_boot_packages: - linux-image-amd64 - busybox-static + - e2fsprogs + - btrfs-tools - openssh-server - python - console-setup - acpi-support - bridge-utils - -_debian_boot_packages: - efi-dmcrypt-lvm: - - busybox-static - - lvm2 - - cryptsetup - - btrfs-tools - - grub-efi-amd64 - - efibootmgr - efi-mdraid-lvm: - - busybox-static - - mdadm - - lvm2 - - btrfs-tools - - grub-efi-amd64 - - efibootmgr - bios-mbr-dmcrypt-lvm: - - busybox-static - - lvm2 - - cryptsetup - - btrfs-tools - - grub-pc - bios-gpt-mdraid-lvm: - - busybox-static - - mdadm - - lvm2 - - btrfs-tools - - grub-pc - -_label_type: - efi-mdraid-lvm: gpt - efi-dmcrypt-lvm: gpt - bios-mbr-dmcrypt-lvm: msdos - bios-gpt-mdraid-lvm: gpt - -_dmcrypt_device_name: "{{inventory_hostname_short}}-crypt0" -_volume_group_name: "{{inventory_hostname_short}}-vg0" -_select_partlabel: "{{inventory_hostname_short}}-select" -_efi_partlabel: "{{inventory_hostname_short}}-efi" - -_mdraid_devices: - bios-mbr-dmcrypt-lvm: [] - efi-dmcrypt-lvm: [] - bios-gpt-mdraid-lvm: - - device: /dev/md/vg0 - devices: "{{ hard_disks | json_query(\"[].partitions[?mdraid=='vg0'][].name\") | map('regex_replace','(.*)','/dev/disk/by-partlabel/\\1') | list }}" - - device: /dev/md/boot - devices: "{{ hard_disks | json_query(\"[].partitions[?mdraid=='boot'][].name\") | map('regex_replace','(.*)','/dev/disk/by-partlabel/\\1') | list }}" - - device: /dev/md/rescue - devices: "{{ hard_disks | json_query(\"[].partitions[?mdraid=='rescue'][].name\") | map('regex_replace','(.*)','/dev/disk/by-partlabel/\\1') | list }}" - efi-mdraid-lvm: - - device: /dev/md/vg0 - devices: "{{ hard_disks | json_query(\"[].partitions[?mdraid=='vg0'][].name\") | map('regex_replace','(.*)','/dev/disk/by-partlabel/\\1') | list }}" - - device: /dev/md/boot - devices: "{{ hard_disks | json_query(\"[].partitions[?mdraid=='boot'][].name\") | map('regex_replace','(.*)','/dev/disk/by-partlabel/\\1') | list }}" - - device: /dev/md/rescue - devices: "{{ hard_disks | json_query(\"[].partitions[?mdraid=='rescue'][].name\") | map('regex_replace','(.*)','/dev/disk/by-partlabel/\\1') | list }}" - -_dmcrypt_devices: - efi-mdraid-lvm: [] - bios-gpt-mdraid-lvm: [] - efi-dmcrypt-lvm: - - device: "{{ _crypt_device[partitioning_profile] }}" - name: "{{inventory_hostname}}-crypt0" - cipher: aes-xts-plain64 - hash: sha512 - key_size: 512 -_crypt_device: - #bios-dmcrypt-lvm: "{{ hard_disk_device }}-part4" - efi-dmcrypt-lvm: /dev/disk/by-partlabel/{{inventory_hostname}}-crypt - bios-gpt-mdraid-lvm: [] - -_volume_groups: - bios-mbr-dmcrypt-lvm: - - name: "{{_volume_group_name}}" - devices: - - /dev/mapper/{{_dmcrypt_device_name}} - efi-dmcrypt-lvm: - - name: "{{_volume_group_name}}" - devices: - - /dev/mapper/{{_dmcrypt_device_name}} - bios-gpt-mdraid-lvm: - - name: "{{_volume_group_name}}" - devices: - - /dev/md/vg0 - efi-mdraid-lvm: - - name: "{{_volume_group_name}}" - devices: - - /dev/md/vg0 - -_logical_volumes_default: - - name: root - size: 32G - volume_group: "{{_volume_group_name}}" - - name: swap - size: 2G - volume_group: "{{_volume_group_name}}" - #- name: home - # size: 100%FREE - # volume_group: vg -_logical_volumes: - bios-mbr-dmcrypt-lvm: "{{_logical_volumes_default}}" - efi-dmcrypt-lvm: "{{_logical_volumes_default}}" - bios-gpt-mdraid-lvm: "{{_logical_volumes_default}}" - efi-mdraid-lvm: "{{_logical_volumes_default}}" - -_fs_uuid_root: "{{ lookup('pipe','uuid -v5 '+filesystem_uuid_namespace+' root') }}" -_fs_uuid_boot: "{{ lookup('pipe','uuid -v5 '+filesystem_uuid_namespace+' boot') }}" -_fs_uuid_rescue: "{{ lookup('pipe','uuid -v5 '+filesystem_uuid_namespace+' rescue') }}" -_fs_uuid_select: "{{ lookup('pipe','uuid -v5 '+filesystem_uuid_namespace+' select') }}" -_fs_uuid_swap: "{{ lookup('pipe','uuid -v5 '+filesystem_uuid_namespace+' swap') }}" - - -_filesystems: - #bios-mbr-dmcrypt-lvm: - # - device: /dev/vg/root - # mount_point: / - # fstype: btrfs - # uuid: "{{ _fs_uuid_root }}" - # - device: "{{ hard_disk_device }}-part2" - # mount_point: /boot - # fstype: btrfs - # uuid: "{{ _fs_uuid_boot }}" - # - device: "{{ hard_disk_device }}-part3" - # mount_point: /boot/rescue - # fstype: btrfs - # uuid: "{{ _fs_uuid_rescue }}" - # - device: "{{ hard_disk_device }}-part1" - # mount_point: /boot/select - # fstype: btrfs - # uuid: "{{ _fs_uuid_select }}" - efi-dmcrypt-lvm: - - device: /dev/{{_volume_group_name}}/root - mount_point: / - fstype: btrfs - uuid: "{{ _fs_uuid_root }}" - - device: /dev/disk/by-partlabel/{{inventory_hostname}}-boot - mount_point: /boot - fstype: btrfs - uuid: "{{ _fs_uuid_boot }}" - - device: /dev/disk/by-partlabel/{{inventory_hostname}}-rescue - mount_point: /boot/rescue - fstype: btrfs - uuid: "{{ _fs_uuid_rescue }}" - - device: /dev/disk/by-partlabel/{{inventory_hostname}}-select - mount_point: /boot/select - fstype: btrfs - uuid: "{{ _fs_uuid_select }}" - - device: /dev/disk/by-partlabel/{{_efi_partlabel}} - mount_point: /boot/efi - fstype: vfat - bios-gpt-mdraid-lvm: - - device: /dev/{{_volume_group_name}}/root - mount_point: / - fstype: btrfs - uuid: "{{ _fs_uuid_root }}" - - device: /dev/md/boot - mount_point: /boot - fstype: btrfs - uuid: "{{ _fs_uuid_boot }}" - - device: /dev/md/rescue - mount_point: /boot/rescue - fstype: btrfs - uuid: "{{ _fs_uuid_rescue }}" - - device: /dev/disk/by-partlabel/{{_select_partlabel}} - mount_point: /boot/select - fstype: btrfs - uuid: "{{ _fs_uuid_select }}" - efi-mdraid-lvm: - - device: /dev/{{_volume_group_name}}/root - mount_point: / - fstype: btrfs - uuid: "{{ _fs_uuid_root }}" - - device: /dev/md/boot - mount_point: /boot - fstype: btrfs - uuid: "{{ _fs_uuid_boot }}" - - device: /dev/md/rescue - mount_point: /boot/rescue - fstype: btrfs - uuid: "{{ _fs_uuid_rescue }}" - - device: /dev/disk/by-partlabel/{{_select_partlabel}} - mount_point: /boot/select - fstype: btrfs - uuid: "{{ _fs_uuid_select }}" - - device: /dev/disk/by-partlabel/{{_efi_partlabel}} - mount_point: /boot/efi - fstype: vfat - -_swap_devices: - bios-mbr-dmcrypt-lvm: - - device: /dev/{{_volume_group_name}}/swap - uuid: "{{ _fs_uuid_swap }}" - efi-dmcrypt-lvm: - - device: /dev/{{_volume_group_name}}/swap - uuid: "{{ _fs_uuid_swap }}" - bios-gpt-mdraid-lvm: - - device: /dev/{{_volume_group_name}}/swap - uuid: "{{ _fs_uuid_swap }}" - efi-mdraid-lvm: - - device: /dev/{{_volume_group_name}}/swap - uuid: "{{ _fs_uuid_swap }}" diff --git a/vars/raid_profiles/mirror.yml b/vars/raid_profiles/mirror.yml new file mode 100644 index 0000000..6570cad --- /dev/null +++ b/vars/raid_profiles/mirror.yml @@ -0,0 +1,17 @@ +mdraid_devices: + - device: /dev/md/boot + level: 1 + devices: "{{ hard_disks | json_query(\"[].partitions[?usage=='boot'][].device\") | list }}" + - device: /dev/md/rescue + level: 1 + devices: "{{ hard_disks | json_query(\"[].partitions[?usage=='rescue'][].device\") | list }}" + - device: /dev/md/system + level: 1 + devices: "{{ hard_disks | json_query(\"[].partitions[?usage=='system'][].device\") | list }}" + +boot_device: /dev/md/boot +rescue_device: /dev/md/rescue +system_device: /dev/md/system + +debian_boot_packages: + - mdadm diff --git a/vars/raid_profiles/single.yml b/vars/raid_profiles/single.yml new file mode 100644 index 0000000..ab1d1c6 --- /dev/null +++ b/vars/raid_profiles/single.yml @@ -0,0 +1,7 @@ +mdraid_devices: [] + +boot_device: "{{ hard_disks | json_query(\"[].partitions[?usage=='boot'][].device\") | first }}" +rescue_device: "{{ hard_disks | json_query(\"[].partitions[?usage=='rescue'][].device\") | first }}" +system_device: "{{ hard_disks | json_query(\"[].partitions[?usage=='system'][].device\") | first }}" + +debian_boot_packages: [] diff --git a/vars/raid_profiles/strip.yml b/vars/raid_profiles/strip.yml new file mode 100644 index 0000000..e68ff16 --- /dev/null +++ b/vars/raid_profiles/strip.yml @@ -0,0 +1,17 @@ +mdraid_devices: + - device: /dev/md/boot + level: 1 + devices: "{{ hard_disks | json_query(\"[].partitions[?usage=='boot'][].device\") | list }}" + - device: /dev/md/rescue + level: 1 + devices: "{{ hard_disks | json_query(\"[].partitions[?usage=='rescue'][].device\") | list }}" + - device: /dev/md/system + level: 0 + devices: "{{ hard_disks | json_query(\"[].partitions[?usage=='system'][].device\") | list }}" + +boot_device: /dev/md/boot +rescue_device: /dev/md/rescue +system_device: /dev/md/system + +debian_boot_packages: + - mdadm