diff --git a/defaults/main.yml b/defaults/main.yml index 6feab78..3842f6a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,5 @@ -partitioning_base_profile: bios-gpt +partitioning_boot_profile: bios-gpt +partitioning_base_profile: data-partition partitioning_raid_profile: "{{ ( hard_disks | length > 1 ) | ternary('mirror','single') }}" partitioning_crypt_profile: none diff --git a/tasks/base_profile.yml b/tasks/base_profile.yml index a7b2e67..d9be1c6 100644 --- a/tasks/base_profile.yml +++ b/tasks/base_profile.yml @@ -5,11 +5,6 @@ file: "base_profiles/{{partitioning_base_profile}}.yml" name: _partitioning_base_profile -- name: set base profile vars - set_fact: - 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: hard_disks: "{{lookup('template','hard_disks_base_profile.json.j2')}}" diff --git a/tasks/boot_profile.yml b/tasks/boot_profile.yml new file mode 100644 index 0000000..8f2c7c8 --- /dev/null +++ b/tasks/boot_profile.yml @@ -0,0 +1,15 @@ +--- + +- name: load boot profile vars + include_vars: + file: "boot_profiles/{{partitioning_boot_profile}}.yml" + name: _partitioning_boot_profile + +- name: set boot profile vars + set_fact: + debian_boot_packages: "{{ _partitioning_boot_profile.debian_boot_packages }}" + grub_bootloader_target: "{{ _partitioning_boot_profile.grub_bootloader_target }}" + +- name: set hard disks boot profile + set_fact: + hard_disks: "{{lookup('template','hard_disks_boot_profile.json.j2')}}" diff --git a/tasks/main.yml b/tasks/main.yml index 34eae5c..4a7daf2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,6 +2,8 @@ - import_tasks: scan.yml +- import_tasks: boot_profile.yml + - import_tasks: base_profile.yml - import_tasks: raid_profile.yml diff --git a/templates/hard_disks_base_profile.json.j2 b/templates/hard_disks_base_profile.json.j2 index 77fd6fc..fdc9980 100644 --- a/templates/hard_disks_base_profile.json.j2 +++ b/templates/hard_disks_base_profile.json.j2 @@ -1,22 +1,10 @@ [ {% 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 %} #} - ] + "device": "{{hd.device}}", + "label_type": "{{ hd.label_type }}", + "partitions": {{ hd.partitions + _partitioning_base_profile.partitions }} }, {% endfor %} ] diff --git a/templates/hard_disks_boot_profile.json.j2 b/templates/hard_disks_boot_profile.json.j2 new file mode 100644 index 0000000..708cf83 --- /dev/null +++ b/templates/hard_disks_boot_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_boot_profile.label_type }}", + "partitions": [ + {% if first_device and _partitioning_boot_profile.partitions_first_device is defined %} + {% for part in _partitioning_boot_profile.partitions_first_device %} + {{part}}, + {% endfor %} + {% endif %} + {% if _partitioning_boot_profile.partitions is defined %} + {% for part in _partitioning_boot_profile.partitions %} + {{part}}, + {% endfor %} + {% endif %} #} + ] +}, +{% endfor %} +] diff --git a/vars/base_profiles/bios-gpt.yml b/vars/base_profiles/bios-gpt.yml deleted file mode 100644 index 6bfa09d..0000000 --- a/vars/base_profiles/bios-gpt.yml +++ /dev/null @@ -1,31 +0,0 @@ -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: -data - start: 2GiB - end: "{{last_partition_end}}" - typecode: 8300 - usage: data - -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 deleted file mode 100644 index beccfbb..0000000 --- a/vars/base_profiles/bios-mbr.yml +++ /dev/null @@ -1,20 +0,0 @@ -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: data - -debian_boot_packages: - - grub-pc - -grub_bootloader_target: i386-pc diff --git a/vars/base_profiles/data-partition.yml b/vars/base_profiles/data-partition.yml new file mode 100644 index 0000000..d9e6f67 --- /dev/null +++ b/vars/base_profiles/data-partition.yml @@ -0,0 +1,7 @@ +partitions: + - prefix: "{{inventory_hostname_short}}-" + suffix: -data + start: 2GiB + end: "{{last_partition_end}}" + typecode: 8300 + usage: data diff --git a/vars/boot_profiles/bios-gpt.yml b/vars/boot_profiles/bios-gpt.yml new file mode 100644 index 0000000..e60eaaa --- /dev/null +++ b/vars/boot_profiles/bios-gpt.yml @@ -0,0 +1,19 @@ +label_type: gpt + +partitions: + - name: bios_boot + start: 1MiB + end: 2MiB + flags: + - bios_grub + - prefix: "{{inventory_hostname_short}}-" + suffix: -boot + start: 2MiB + end: 1GiB + typecode: 8300 + usage: boot + +debian_boot_packages: + - grub-pc + +grub_bootloader_target: i386-pc diff --git a/vars/boot_profiles/bios-mbr.yml b/vars/boot_profiles/bios-mbr.yml new file mode 100644 index 0000000..badfed4 --- /dev/null +++ b/vars/boot_profiles/bios-mbr.yml @@ -0,0 +1,12 @@ +label_type: msdos + +partitions: + - type: primary + start: 1MiB + end: 1GiB + usage: boot + +debian_boot_packages: + - grub-pc + +grub_bootloader_target: i386-pc diff --git a/vars/base_profiles/efi.yml b/vars/boot_profiles/efi.yml similarity index 100% rename from vars/base_profiles/efi.yml rename to vars/boot_profiles/efi.yml diff --git a/vars/main.yml b/vars/main.yml index 0dffa30..238b156 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,5 +1,5 @@ -_host_vars_filename: partitioning -_host_vars_default: {} +_host_vars_filename: partitioning +_host_vars_default: {} _host_vars: hard_disks: "{{ hard_disks }}" mdraid_devices: "{{ mdraid_devices }}" diff --git a/vars/raid_profiles/mirror.yml b/vars/raid_profiles/mirror.yml index e949f67..ceff8f2 100644 --- a/vars/raid_profiles/mirror.yml +++ b/vars/raid_profiles/mirror.yml @@ -2,9 +2,6 @@ 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/data level: 1 devices: "{{ hard_disks | json_query(\"[].partitions[?usage=='data'][].device\") | list }}" diff --git a/vars/raid_profiles/strip.yml b/vars/raid_profiles/strip.yml index 2c09ec0..bd1cfe8 100644 --- a/vars/raid_profiles/strip.yml +++ b/vars/raid_profiles/strip.yml @@ -2,9 +2,6 @@ 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/data level: 0 devices: "{{ hard_disks | json_query(\"[].partitions[?usage=='data'][].device\") | list }}"