From a86c2cdfb6e96fea6bd838a85604b97e1c9221f1 Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Mon, 4 Dec 2017 03:48:27 +0000 Subject: [PATCH] improvements --- tasks/base_profile.yml | 3 +- tasks/main.yml | 4 ++ tasks/profile.yml | 15 ++++++ tasks/volumes.yml | 7 +++ templates/logical_volume_filesystems.json.j2 | 13 +++++ templates/logical_volumes.json.j2 | 13 +++++ vars/base_profiles/bios-gpt.yml | 2 + vars/base_profiles/bios-mbr.yml | 2 + vars/base_profiles/efi.yml | 2 + vars/main.yml | 52 ++++---------------- vars/profile.yml | 41 +++++++++++++++ 11 files changed, 110 insertions(+), 44 deletions(-) create mode 100644 tasks/profile.yml create mode 100644 templates/logical_volume_filesystems.json.j2 create mode 100644 templates/logical_volumes.json.j2 create mode 100644 vars/profile.yml diff --git a/tasks/base_profile.yml b/tasks/base_profile.yml index 6b363d2..a7b2e67 100644 --- a/tasks/base_profile.yml +++ b/tasks/base_profile.yml @@ -7,7 +7,8 @@ - name: set base profile vars set_fact: - debian_boot_packages: "{{ debian_boot_packages | union(_partitioning_base_profile.debian_boot_packages) }}" + debian_boot_packages: "{{ _partitioning_base_profile.debian_boot_packages }}" + grub_bootloader_target: "{{ _partitioning_base_profile.grub_bootloader_target }}" - name: set hard disks base profile set_fact: diff --git a/tasks/main.yml b/tasks/main.yml index 47968b1..34eae5c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,8 +8,12 @@ - import_tasks: crypt_profile.yml +- import_tasks: profile.yml + - import_tasks: efi_filesystem.yml +- import_tasks: volumes.yml + - import_tasks: filesystems.yml - import_tasks: swap_devices.yml diff --git a/tasks/profile.yml b/tasks/profile.yml new file mode 100644 index 0000000..f6ea322 --- /dev/null +++ b/tasks/profile.yml @@ -0,0 +1,15 @@ +--- + +- name: load profile vars + include_vars: + file: profile.yml + name: _partitioning_profile + +- name: set profile vars + set_fact: + volume_groups: "{{ _partitioning_profile.volume_groups }}" + logical_volumes: "{{ _partitioning_profile.logical_volumes }}" + filesystems: "{{ _partitioning_profile.filesystems }}" + swap_devices: "{{ _partitioning_profile.swap_devices }}" + grub_cmdline_linux: "{{ _partitioning_profile.grub_cmdline_linux }}" + debian_boot_packages: "{{ debian_boot_packages|union(_partitioning_profile.debian_boot_packages) }}" diff --git a/tasks/volumes.yml b/tasks/volumes.yml index e69de29..44d8dcb 100644 --- a/tasks/volumes.yml +++ b/tasks/volumes.yml @@ -0,0 +1,7 @@ +--- + +- name: set additional logical volumes + set_fact: + logical_volumes: "{{lookup('template','logical_volumes.json.j2')}}" + filesystems: "{{lookup('template','logical_volume_filesystems.json.j2')}}" + when: partitioning_profile_volumes is defined diff --git a/templates/logical_volume_filesystems.json.j2 b/templates/logical_volume_filesystems.json.j2 new file mode 100644 index 0000000..499a342 --- /dev/null +++ b/templates/logical_volume_filesystems.json.j2 @@ -0,0 +1,13 @@ +[ +{% for fs in filesystems %} +{{fs|to_json}}, +{% endfor %} +{% for vol in partitioning_profile_volumes %} +{% set fs = vol.fs %} +{% set fs = fs | combine({ + 'label': vol.name, + 'device': "/dev/"+primary_volume_group_name+"/"+vol.name +}) %} +{{fs|to_json}}, +{% endfor %} +] diff --git a/templates/logical_volumes.json.j2 b/templates/logical_volumes.json.j2 new file mode 100644 index 0000000..982b083 --- /dev/null +++ b/templates/logical_volumes.json.j2 @@ -0,0 +1,13 @@ +[ +{% for lv in logical_volumes %} +{{lv|to_json}}, +{% endfor %} +{% for vol in partitioning_profile_volumes %} +{% set lv = vol.lv %} +{% set lv = lv | combine({ + 'volume_group': primary_volume_group_name +}) %} +{% set lv = lv | combine({ 'name': vol.name }) %} +{{lv|to_json}}, +{% endfor %} +] diff --git a/vars/base_profiles/bios-gpt.yml b/vars/base_profiles/bios-gpt.yml index 19d5d81..48a5ead 100644 --- a/vars/base_profiles/bios-gpt.yml +++ b/vars/base_profiles/bios-gpt.yml @@ -27,3 +27,5 @@ partitions: debian_boot_packages: - grub-pc + +grub_bootloader_target: i386-pc diff --git a/vars/base_profiles/bios-mbr.yml b/vars/base_profiles/bios-mbr.yml index b2d3246..53a636e 100644 --- a/vars/base_profiles/bios-mbr.yml +++ b/vars/base_profiles/bios-mbr.yml @@ -16,3 +16,5 @@ partitions: debian_boot_packages: - grub-pc + +grub_bootloader_target: i386-pc diff --git a/vars/base_profiles/efi.yml b/vars/base_profiles/efi.yml index 440563d..19ee553 100644 --- a/vars/base_profiles/efi.yml +++ b/vars/base_profiles/efi.yml @@ -31,3 +31,5 @@ partitions: debian_boot_packages: - efibootmgr - grub-efi-amd64 + +grub_bootloader_target: x86_64-efi diff --git a/vars/main.yml b/vars/main.yml index 1f186e1..0dffa30 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,53 +1,19 @@ _host_vars_filename: partitioning _host_vars_default: {} _host_vars: - 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 }}" + 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 + grub_cmdline_linux: "{{ grub_cmdline_linux }}" + grub_bootloader_target: "{{ grub_bootloader_target }}" _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 diff --git a/vars/profile.yml b/vars/profile.yml new file mode 100644 index 0000000..c904b52 --- /dev/null +++ b/vars/profile.yml @@ -0,0 +1,41 @@ + +volume_groups: + - name: "{{primary_volume_group_name}}" + devices: + - "{{ system_device }}" + +logical_volumes: + - name: root + size: "{{root_partition_default_size}}" + volume_group: "{{primary_volume_group_name}}" + - name: swap + size: "{{swap_partition_default_size}}" + volume_group: "{{primary_volume_group_name}}" + +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 + +swap_devices: + - device: /dev/{{primary_volume_group_name}}/swap + +grub_cmdline_linux: root=/dev/{{primary_volume_group_name}}/root + +debian_boot_packages: + - linux-image-amd64 + - busybox-static + - lvm2 + - e2fsprogs + - btrfs-tools + - openssh-server + - python + - console-setup + - acpi-support + - bridge-utils