浏览代码

more flexible partitioning profiles

master
父节点
当前提交
d9d8bedb12
共有 4 个文件被更改,包括 232 次插入95 次删除
  1. +12
    -0
      tasks/main.yml
  2. +21
    -0
      templates/hard_disks.json.j2
  3. +91
    -0
      templates/partitions.json.j2
  4. +108
    -95
      vars/main.yml

+ 12
- 0
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

+ 21
- 0
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 %}#}
]

+ 91
- 0
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 %}
]

+ 108
- 95
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

正在加载...
取消
保存