From d9d8bedb126614e35b1767366128b14f45a2d669 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Wed, 11 Oct 2017 12:49:36 +0000 Subject: [PATCH] more flexible partitioning profiles --- tasks/main.yml | 12 +++ templates/hard_disks.json.j2 | 21 ++++ templates/partitions.json.j2 | 91 ++++++++++++++++ vars/main.yml | 203 +++++++++++++++++++---------------- 4 files changed, 232 insertions(+), 95 deletions(-) create mode 100644 templates/hard_disks.json.j2 create mode 100644 templates/partitions.json.j2 diff --git a/tasks/main.yml b/tasks/main.yml index 902dbab..e9a3a36 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,3 +1,15 @@ --- +- name: set filesystem uuid namespace + set_fact: + filesystem_uuid_namespace: "{{ lookup('pipe','uuid -v4') }}" + +- name: set hard_disks + set_fact: + hard_disks: "{{lookup('template','hard_disks.json.j2')}}" + +#- name: _host_vars debug +# debug: +# msg: "{{_host_vars}}" + - include: host_vars.yml diff --git a/templates/hard_disks.json.j2 b/templates/hard_disks.json.j2 new file mode 100644 index 0000000..0e62b72 --- /dev/null +++ b/templates/hard_disks.json.j2 @@ -0,0 +1,21 @@ +[ +{# +{% if hard_disks is defined %} +{% for hard_disk in hard_disks %} +{{hard_disk}}, +{% endfor %} +{% else %} +#} +{% set efi_device_name = ansible_devices.keys() | first %} +{% for device in ansible_devices.keys() %} +{% set name = device %} +{% set device = '/dev/' + device %} +{ + "device": "{{device}}", + "name": "{{name}}", + "label_type": "{{ _label_type[partitioning_profile] }}", + "partitions": {% include "partitions.json.j2" %} +}, +{% endfor %} +{#{% endif %}#} +] diff --git a/templates/partitions.json.j2 b/templates/partitions.json.j2 new file mode 100644 index 0000000..7a90ece --- /dev/null +++ b/templates/partitions.json.j2 @@ -0,0 +1,91 @@ +[ +{% set partition_name_prefix = inventory_hostname_short + '-' + name %} +{% if partitioning_profile == "bios-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": "-1MiB" +} +{% 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": "-1MiB" +} +{% endif %} +{% if partitioning_profile == "efi-mdraid-lvm" %} +{% if efi_device_name == name %} +{ + "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": "-1MiB", + "mdraid": "vg0" +} +{% endif %} +] diff --git a/vars/main.yml b/vars/main.yml index 16f4dc6..bf150a9 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,133 +1,146 @@ -_host_vars_filename: partitions +_host_vars_filename: partitioning _host_vars: hard_disks: "{{ hard_disks }}" - mdraid_devices: "{{ mdraid_devices }}" - dmcrypt_devices: "{{ dmcrypt_devices }}" - volume_groups: "{{ volume_groups }}" - logical_volumes: "{{ logical_volumes }}" - filesystems: "{{ filesystems }}" - - -filesystem_uuid_namespace: "{{ lookup('pipe','uuid -v4') }}" - -_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') }}" - -hard_disks: - - device: "{{ hard_disk_device }}" - label_type: "{{ _label_type[installation_profile] }}" - partitions: "{{ _partitions[installation_profile] }}" + 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] }}" _label_type: - bios: msdos - efi: gpt + efi-mdraid-lvm: gpt + efi-dmcrypt-lvm: gpt + bios-dmcrypt-lvm: msdos -_partitions: - bios: - - 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: -1s - efi: - - part_type: ESP - start: 256MiB - end: 768MiB - - name: select - start: 768MiB - end: 1GiB - - name: "{{inventory_hostname}}-boot0" - typecode: 8300 - start: 1GiB - end: 2GiB - - name: "{{inventory_hostname}}-rescue0" - typecode: 8300 - start: 2GiB - end: 6GiB - - name: "{{inventory_hostname}}-crypt0" - typecode: 8300 - start: 6GiB - end: -1s +_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: [] +_mdraid_devices: + bios-dmcrypt-lvm: [] + efi-dmcrypt-lvm: [] + 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: - - device: "{{ _crypt_device[installation_profile] }}" - name: "{{inventory_hostname}}-crypt0" - cipher: aes-xts-plain64 - hash: sha512 - key_size: 512 +_dmcrypt_devices: + efi-mdraid-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 -_crypt_device: - bios: "{{ hard_disk_device }}-part4" - efi: /dev/disk/by-partlabel/{{inventory_hostname}}-crypt -volume_groups: - - name: vg - devices: - - /dev/mapper/{{inventory_hostname}}-crypt0 +_volume_groups: + bios-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}} + efi-mdraid-lvm: + - name: "{{_volume_group_name}}" + devices: + - /dev/md/vg0 -logical_volumes: - - name: root - size: 32G - volume_group: vg - - name: swap - size: 1G - volume_group: vg - - name: home - size: 100%FREE - volume_group: vg +_logical_volumes: + bios-dmcrypt-lvm: + - name: root + size: 32G + volume_group: "{{_volume_group_name}}" + - name: swap + size: 1G + volume_group: "{{_volume_group_name}}" + efi-dmcrypt-lvm: + - name: root + size: 32G + volume_group: "{{_volume_group_name}}" + - name: swap + size: 1G + volume_group: "{{_volume_group_name}}" + efi-mdraid-lvm: + - name: root + size: 32G + volume_group: "{{_volume_group_name}}" + - name: swap + size: 1G + volume_group: "{{_volume_group_name}}" + #- name: home + # size: 100%FREE + # volume_group: vg + +_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') }}" -filesystems: "{{ _filesystems[installation_profile] }}" _filesystems: - bios: - - device: /dev/vg/root + #bios-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: "{{ hard_disk_device }}-part2" + - device: /dev/disk/by-partlabel/{{inventory_hostname}}-boot mount_point: /boot fstype: btrfs uuid: "{{ _fs_uuid_boot }}" - - device: "{{ hard_disk_device }}-part3" + - device: /dev/disk/by-partlabel/{{inventory_hostname}}-rescue mount_point: /boot/rescue fstype: btrfs uuid: "{{ _fs_uuid_rescue }}" - - device: "{{ hard_disk_device }}-part1" + - device: /dev/disk/by-partlabel/{{inventory_hostname}}-select mount_point: /boot/select fstype: btrfs uuid: "{{ _fs_uuid_select }}" - efi: - - device: /dev/vg/root + - device: /dev/disk/by-partlabel/{{_efi_partlabel}} + mount_point: /boot/efi + fstype: vfat + efi-mdraid-lvm: + - device: /dev/{{_volume_group_name}}/root mount_point: / fstype: btrfs uuid: "{{ _fs_uuid_root }}" - - device: /dev/disk/by-partlabel/{{inventory_hostname}}-boot + - device: /dev/md/boot mount_point: /boot fstype: btrfs uuid: "{{ _fs_uuid_boot }}" - - device: /dev/disk/by-partlabel/{{inventory_hostname}}-rescue + - device: /dev/md/rescue mount_point: /boot/rescue fstype: btrfs uuid: "{{ _fs_uuid_rescue }}" - - device: /dev/disk/by-partlabel/{{inventory_hostname}}-select + - device: /dev/disk/by-partlabel/{{_select_partlabel}} mount_point: /boot/select fstype: btrfs uuid: "{{ _fs_uuid_select }}" - - device: /dev/disk/by-partuuid/C12A7328-F81F-11D2-BA4B-00A0C93EC93B + - device: /dev/disk/by-partlabel/{{_efi_partlabel}} mount_point: /boot/efi - fstype: fat - uuid: C12A7328-F81F-11D2-BA4B-00A0C93EC93B + fstype: vfat