ansible-lint --fix

This commit is contained in:
Mark Riedesel 2024-11-22 10:45:41 -06:00
parent 5634cd32d3
commit faa046aa21
21 changed files with 181 additions and 179 deletions

View file

@ -1,11 +1,11 @@
---
- name: Inspect EFI boot partitions
become: true
command: "blkid {{ item }}"
ansible.builtin.command: "blkid {{ item }}"
loop: "{{ base_efi_partitions | default([]) }}"
register: blkid
- name: Format EFI partitions fat32
command: "mkfs.vfat -v -F 32 -n EFI {{ item.item }}"
ansible.builtin.command: "mkfs.vfat -v -F 32 -n EFI {{ item.item }}"
loop: "{{ blkid.results | rejectattr('stdout', 'contains', 'TYPE=\"vfat\"') }}"
register: mkfs_vfat_efi

View file

@ -1,45 +1,45 @@
---
- name: Check for existing zroot zfs volume
command: zpool list -Ho name zroot
ansible.builtin.command: zpool list -Ho name zroot
register: zroot_check
ignore_errors: true
- block:
- name: Initialize disk device to id table
set_fact:
partition_device_to_ids: {}
- when: zroot_check.rc != 0
- name: Create disk device to id table
set_fact:
partition_device_to_ids: >-
{{
partition_device_to_ids
| combine({ item.value: (partition_device_to_ids[item.value] | default([])) + [item.key] })
}}
with_items: "{{ base_partitions_by_id | dict2items }}"
block:
- name: Initialize disk device to id table
ansible.builtin.set_fact:
partition_device_to_ids: {}
- debug:
var: base_root_partitions | map('extract', partition_device_to_ids) | map('first')
- name: Create disk device to id table
ansible.builtin.set_fact:
partition_device_to_ids: >-
{{
partition_device_to_ids
| combine({ item.value: (partition_device_to_ids[item.value] | default([])) + [item.key] })
}}
with_items: "{{ base_partitions_by_id | dict2items }}"
- name: Create zroot volume
become: true
command: >-
zpool create -f -o ashift=12
-o autotrim=on
-O devices=off
-O relatime=on
-O xattr=sa
-O acltype=posixacl
-O normalization=formD
-O compression=lz4
-O canmount=off
-O mountpoint=none
-R /mnt
zroot {{ mirror }} {{ base_root_partitions | map('extract', partition_device_to_ids) | map('first') | list | join(' ') }}
vars:
mirror: "{{ 'mirror' if base_root_partitions | length > 1 else '' }}"
when: zroot_check.rc != 0
- ansible.builtin.debug:
var: base_root_partitions | map('extract', partition_device_to_ids) | map('first')
- name: Create zroot volume
become: true
ansible.builtin.command: >-
zpool create -f -o ashift=12
-o autotrim=on
-O devices=off
-O relatime=on
-O xattr=sa
-O acltype=posixacl
-O normalization=formD
-O compression=lz4
-O canmount=off
-O mountpoint=none
-R /mnt
zroot {{ mirror }} {{ base_root_partitions | map('extract', partition_device_to_ids) | map('first') | list | join(' ') }}
vars:
mirror: "{{ 'mirror' if base_root_partitions | length > 1 else '' }}"
- name: Create zroot/ROOT and zroot/DATA volumes
community.general.zfs:
name: "zroot/{{ item }}"
@ -64,7 +64,6 @@
mountpoint: /home
- name: Export zroot pool
command: zpool export zroot
ansible.builtin.command: zpool export zroot
- name: Import zroot pool (-R /mnt)
command: zpool import -R /mnt zroot -N
ansible.builtin.command: zpool import -R /mnt zroot -N

View file

@ -1,12 +1,12 @@
---
- name: Initialize swap space
become: true
command: "blkid {{item}}"
ansible.builtin.command: "blkid {{item}}"
loop: "{{ base_swap_partitions | default([]) }}"
register: blkid
- name: Swap devices without swap filesystems present
become: true
command: "mkswap --verbose {{item.item}}"
ansible.builtin.command: "mkswap --verbose {{item.item}}"
loop: "{{ blkid.results | rejectattr('stdout', 'contains', 'TYPE=\"swap\"') }}"
register: mkswap

View file

@ -1,14 +1,14 @@
---
- name: archinstall | install os | check for presence of previously pacstrapped /mnt
stat:
ansible.builtin.stat:
path: /mnt/usr/lib
register: existing_pacstrap
- debug:
- ansible.builtin.debug:
var: existing_pacstrap
- name: archinstall | install os | pacstrap
shell: "pacstrap /mnt {{ packages | join(' ') }}"
ansible.builtin.command: "pacstrap /mnt {{ packages | join(' ') }}"
vars:
packages:
- ansible
@ -26,56 +26,54 @@
when: not existing_pacstrap.stat.exists
- name: archinstall | install os | copy pacman mirrorlist
copy:
ansible.builtin.copy:
remote_src: true
src: /etc/pacman.d/mirrorlist
dest: /mnt/etc/pacman.d/mirrorlist
- name: archinstall | install os | propagate root authorized keys
copy:
ansible.builtin.copy:
remote_src: true
src: /root/.ssh/authorized_keys
dest: /mnt/root/.ssh/authorized_keys
- name: archinstall | install os | passwordless sudo for group wheel
copy:
ansible.builtin.copy:
content: "%wheel ALL=(ALL) NOPASSWD: ALL"
dest: /mnt/etc/sudoers.d/wheel-group-nopasswd
- name: archinstall | install os | set timezone
file:
ansible.builtin.file:
src: /usr/share/zoneinfo/US/Central
dest: /mnt/etc/localtime
state: link
- name: archinstall | install os | enable en_US locales
command: sed -i 's/^#en_US/en_US/' /mnt/etc/locale.gen
ansible.builtin.command: sed -i 's/^#en_US/en_US/' /mnt/etc/locale.gen
- name: archinstall | install os | generate locales
command: arch-chroot /mnt locale-gen
ansible.builtin.command: arch-chroot /mnt locale-gen
- name: archinstall | install os | generate template for arch-chroot installation
template:
ansible.builtin.template:
src: arch_chroot_install.sh
dest: /mnt/arch_chroot_install.sh
mode: "0755"
- name: archinstall | install os | set hostname
copy:
ansible.builtin.copy:
dest: /mnt/etc/hostname
content: |
{{ inventory_hostname }}
- name: archinstall | install os | run installation script in arch-chroot
command: arch-chroot /mnt /arch_chroot_install.sh
ansible.builtin.command: arch-chroot /mnt /arch_chroot_install.sh
register: chroot
- name: archinstall | install os | arch-chroot install output
debug:
ansible.builtin.debug:
msg: "{{ chroot.stdout_lines }}"
- name: archinstall | install os | remove arch-chroot installation script
file:
ansible.builtin.file:
path: /mnt/arch_chroot_install.sh
state: absent

View file

@ -1,4 +1,4 @@
---
- name: Select fastest Arch repository mirrors
command:
ansible.builtin.command:
cmd: reflector --country US --latest 5 --sort rate --save /etc/pacman.d/mirrorlist

View file

@ -6,8 +6,8 @@
register: base_root_disks_info
loop: "{{ base_root_disks | list }}"
- name: partition | ensure efi is not mounted
mount:
- name: partition | Ensure efi is not mounted
ansible.posix.mount:
path: /mnt/boot/efi
state: unmounted
@ -15,20 +15,21 @@
ansible.builtin.set_fact:
base_root_usable_mib: "{{ (base_root_disks_info.results | map(attribute='disk.size') | min | int) - 1 }}"
- debug: var=base_root_usable_mib
- ansible.builtin.debug:
var: base_root_usable_mib
- name: Calculate disk utilization percentage
ansible.builtin.set_fact:
base_root_usable_mib: "{{ base_root_usable_mib|int - ((base_root_usable_mib|float) * (0.01 * (base_root_free_percent|float))) | round(method='floor') | int }}"
base_root_usable_mib: "{{ base_root_usable_mib | int - ((base_root_usable_mib | float) * (0.01 * (base_root_free_percent | float))) | round(method='floor') |
int }}"
- name: Calculate zfs volume size
set_fact:
base_root_zpool_mib: "{{ base_root_usable_mib|int - fixed_size_partitions|int }}"
ansible.builtin.set_fact:
base_root_zpool_mib: "{{ base_root_usable_mib | int - fixed_size_partitions | int }}"
vars:
fixed_size_partitions: "{{ base_root_swap_mib|int + base_root_efi_mib|int }}"
fixed_size_partitions: "{{ base_root_swap_mib | int + base_root_efi_mib | int }}"
#
- name: Calculate partition layouts
set_fact:
ansible.builtin.set_fact:
partition_ranges: >-
{{
(partition_ranges|d([])) + [{
@ -47,11 +48,11 @@
- name: swap
size_mib: "{{ base_root_swap_mib }}"
- debug:
- ansible.builtin.debug:
var: partition_ranges
- name: Initialize partition facts
set_fact:
ansible.builtin.set_fact:
base_efi_partitions: []
base_root_partitions: []
base_swap_partitions: []
@ -61,14 +62,14 @@
become: true
vars:
part_index: 0
parted:
community.general.parted:
label: gpt
unit: MiB
name: EFI Boot
device: "{{ item.disk.dev }}"
number: "{{ part_index + 1 }}"
flags: [ boot, esp ]
part_start: "{{ [partition_ranges[part_index].begin, 1]|max }}MiB"
flags: [boot, esp]
part_start: "{{ [partition_ranges[part_index].begin, 1] | max }}MiB"
part_end: "{{ partition_ranges[part_index].end }}MiB"
state: present
fs_type: fat32
@ -76,12 +77,12 @@
register: parted_create
- name: Collect EFI partition devices
shell: "lsblk -r --noheadings -o PATH {{ item }} | sort"
ansible.builtin.shell: "lsblk -r --noheadings -o PATH {{ item }} | sort"
register: lsblk
loop: "{{ parted_create.results | map(attribute='disk.dev') }}"
- name: Store EFI partition devices
set_fact:
ansible.builtin.set_fact:
base_efi_partitions: >-
{{ base_efi_partitions|d([]) + [
item[part_index+1]
@ -91,14 +92,13 @@
vars:
part_index: 0
- debug: var=base_efi_partitions
#### zroot
- ansible.builtin.debug:
var: base_efi_partitions
- name: Create root zvol partition
become: true
vars:
part_index: 1
parted:
community.general.parted:
label: gpt
unit: MiB
name: ArchLinux ZFS Root
@ -111,12 +111,12 @@
register: parted_create
- name: Collect root zvol partition devices
shell: "lsblk -r --noheadings -o PATH {{ item }} | sort"
ansible.builtin.shell: "lsblk -r --noheadings -o PATH {{ item }} | sort"
register: lsblk
loop: "{{ parted_create.results | map(attribute='disk.dev') }}"
- name: Store root zvol partition devices
set_fact:
ansible.builtin.set_fact:
base_root_partitions: >-
{{ base_root_partitions|d([]) + [
item[part_index+1]
@ -131,7 +131,7 @@
become: true
vars:
part_index: 2
parted:
community.general.parted:
label: gpt
unit: MiB
device: "{{ item.disk.dev }}"
@ -145,13 +145,13 @@
when: base_root_swap_mib is defined and base_root_swap_mib|int > 0
- name: Collect swap partition devices
shell: "lsblk -r --noheadings -o PATH {{ item }} | sort"
ansible.builtin.shell: "lsblk -r --noheadings -o PATH {{ item }} | sort"
register: lsblk
loop: "{{ parted_create.results | map(attribute='disk.dev') }}"
when: base_root_swap_mib is defined and base_root_swap_mib|int > 0
- name: Store swap partition devices
set_fact:
ansible.builtin.set_fact:
base_swap_partitions: >-
{{ base_swap_partitions|d([]) + [
item[part_index+1]
@ -163,18 +163,18 @@
when: base_root_swap_mib is defined and base_root_swap_mib|int > 0
- name: Analyze resulting partition layouts
parted:
community.general.parted:
unit: MiB
device: "{{ item }}"
register: base_root_disks_info
loop: "{{ base_root_disks | list }}"
- name: Collect disk device identifiers
shell: "for x in /dev/disk/by-id/*; do echo $x $(realpath $x); done"
ansible.builtin.shell: "for x in /dev/disk/by-id/*; do echo $x $(realpath $x); done"
register: disk_realpaths
- name: Collect disk device identifiers into a base_partitions_by_id dictionary
set_fact:
ansible.builtin.set_fact:
base_partitions_by_id: >-
{{
dict(
@ -184,6 +184,9 @@
)
}}
- debug: var=base_efi_partitions
- debug: var=base_root_partitions
- debug: var=base_swap_partitions
- ansible.builtin.debug:
var: base_efi_partitions
- ansible.builtin.debug:
var: base_root_partitions
- ansible.builtin.debug:
var: base_swap_partitions

View file

@ -1,10 +1,11 @@
- name: archinstall | re-create post-installation snapshot of zroot/ROOT/arch
---
- name: archinstall | Re-create post-installation snapshot of zroot/ROOT/arch
community.general.zfs:
name: zroot/ROOT/arch@post-installation
state: "{{ item }}"
with_items: [absent, present]
- name: archinstall | re-create post-installation snapshot of zroot/DATA/home
- name: archinstall | Re-create post-installation snapshot of zroot/DATA/home
community.general.zfs:
name: zroot/DATA/home@post-installation
state: "{{ item }}"

View file

@ -1,10 +1,8 @@
---
- name: Mount arch zroot
command: zfs mount zroot/ROOT/arch
ansible.builtin.command: zfs mount zroot/ROOT/arch
- name: Mount all other zroot mountpoints
command: zfs mount -a
ansible.builtin.command: zfs mount -a
- name: Create zroot destination directories
ansible.builtin.file:
path: "/mnt{{ item }}"
@ -13,8 +11,8 @@
- /etc/zfs
- /boot/efi
- debug: var=base_efi_partitions
- ansible.builtin.debug:
var: base_efi_partitions
- name: Mount EFI
ansible.posix.mount:
path: /mnt/boot/efi
@ -22,11 +20,9 @@
fstype: vfat
state: mounted
- name: zfs | set zroot bootfs to arch
command: zpool set bootfs=zroot/ROOT/arch zroot
- name: zfs | set cachefile
command: zpool set cachefile=/etc/zfs/zpool.cache zroot
- name: zfs | copy cache file to chroot
command: cp /etc/zfs/zpool.cache /mnt/etc/zfs
- name: zfs | Set zroot bootfs to arch
ansible.builtin.command: zpool set bootfs=zroot/ROOT/arch zroot
- name: zfs | Set cachefile
ansible.builtin.command: zpool set cachefile=/etc/zfs/zpool.cache zroot
- name: zfs | Copy cache file to chroot
ansible.builtin.command: cp /etc/zfs/zpool.cache /mnt/etc/zfs