2021-03-14 12:41:46 +00:00
|
|
|
---
|
2021-03-18 21:35:44 +00:00
|
|
|
# tasks file for ansible-arch-provissionninga
|
|
|
|
#
|
2021-03-14 12:41:46 +00:00
|
|
|
- name: Abort if the host is not booted from the Arch install media
|
|
|
|
fail:
|
2021-03-18 21:35:44 +00:00
|
|
|
msg: "This host {{ ansible_nodename }} is not booted from the Arch install media!"
|
2021-03-14 12:41:46 +00:00
|
|
|
when: ansible_nodename != 'archiso'
|
|
|
|
|
|
|
|
- name: Synchronize clock via NTP
|
|
|
|
command: timedatectl set-ntp true
|
|
|
|
|
|
|
|
- name: wipe drives
|
2021-03-18 21:35:44 +00:00
|
|
|
command: wipefs -a {{ item.device }}
|
2021-03-14 12:41:46 +00:00
|
|
|
loop: '{{ partition_table }}'
|
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
|
2021-03-14 12:41:46 +00:00
|
|
|
- name: create partition
|
2021-03-18 21:35:44 +00:00
|
|
|
parted:
|
|
|
|
device: "{{ item.0.device }}"
|
2022-09-12 19:37:29 +00:00
|
|
|
label: "{% if provissionning_UEFI_Enable == True %}gpt{% else %}msdos{% endif %}"
|
2021-03-18 21:35:44 +00:00
|
|
|
number: "{{ item.1.number }}"
|
|
|
|
part_start: "{{ item.1.part_start | default('0%') }}"
|
|
|
|
part_end: "{{ item.1.part_end | default('100%') }}"
|
2021-03-21 11:45:52 +00:00
|
|
|
#name: "{{ item.1.name }} |default('none')"
|
2021-03-18 21:35:44 +00:00
|
|
|
flags: "{{ item.1.flags }}"
|
|
|
|
state: present
|
|
|
|
loop: '{{ partition_table|subelements("settings") }}'
|
2021-03-14 12:41:46 +00:00
|
|
|
|
|
|
|
- name: create filesystems
|
2021-03-18 21:35:44 +00:00
|
|
|
filesystem:
|
|
|
|
dev: "{{ item.0.device }}{{ item.1.number }}"
|
|
|
|
fstype: "{{ item.1.fstype }}"
|
|
|
|
force: yes
|
|
|
|
loop: '{{ partition_table|subelements("settings") }}'
|
|
|
|
when: item.1.format == True
|
2021-03-14 12:41:46 +00:00
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: Mount filesystems
|
|
|
|
mount:
|
|
|
|
src: "{{ item.0.device }}{{ item.1.number }}"
|
|
|
|
fstype: "{{ item.1.fstype }}"
|
|
|
|
path: "{{ item.1.mountpath }}"
|
|
|
|
state: "mounted"
|
|
|
|
loop: '{{ mount_table|subelements("settings") }}'
|
|
|
|
when: item.1.mountpath is defined
|
2021-03-14 12:41:46 +00:00
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: enable swap
|
|
|
|
command: mkswap "{{ item.0.device }}{{ item.1.number }}"
|
|
|
|
loop: '{{ partition_table|subelements("settings") }}'
|
|
|
|
when: item.1.fstype == "swap"
|
2021-03-14 12:41:46 +00:00
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: add local repo to mirrorlist
|
|
|
|
become: yes
|
|
|
|
lineinfile:
|
|
|
|
path: /etc/pacman.d/mirrorlist
|
|
|
|
line: "Server= {{system_arch_local_mirror}}/$repo/os/$arch"
|
|
|
|
state: present
|
|
|
|
insertbefore: BOF
|
|
|
|
when: system_arch_local_mirror is defined
|
|
|
|
- name: update archlinux-keyring
|
|
|
|
pacman:
|
2021-03-21 11:45:52 +00:00
|
|
|
update_cache: yes
|
2021-03-18 21:35:44 +00:00
|
|
|
name: archlinux-keyring
|
|
|
|
state: latest
|
2021-03-14 12:41:46 +00:00
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: populate key
|
|
|
|
command: "{{ item }}"
|
|
|
|
loop:
|
|
|
|
- pacman-key --init
|
|
|
|
- pacman-key --populate archlinux
|
2021-03-14 12:41:46 +00:00
|
|
|
|
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: pacstrap
|
|
|
|
shell:
|
|
|
|
cmd: "pacstrap /mnt {{ provissionning_pacstrap_software | join(' ') }}"
|
2021-03-14 12:41:46 +00:00
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: Generate fstab
|
|
|
|
shell:
|
|
|
|
cmd: genfstab -U /mnt >> /mnt/etc/fstab
|
|
|
|
- name: Enable sshd
|
|
|
|
command: arch-chroot /mnt systemctl enable sshd
|
|
|
|
|
|
|
|
- name: Enable service
|
|
|
|
command: "arch-chroot /mnt systemctl enable {{ item }}"
|
|
|
|
loop: "{{ provissionning_enable_service }}"
|
2021-03-14 12:41:46 +00:00
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: Set up initramfs
|
|
|
|
block:
|
|
|
|
- name: Add mkinitcpio.conf hooks
|
|
|
|
lineinfile:
|
|
|
|
dest: /mnt/etc/mkinitcpio.conf
|
|
|
|
regexp: ^HOOKS=
|
|
|
|
line: "HOOKS=( {{provissionning_initramfs_hooks | join(' ')}} )"
|
|
|
|
- name: Create new initramfs
|
|
|
|
command: arch-chroot /mnt mkinitcpio -p linux
|
|
|
|
- name: Set up grub
|
|
|
|
block:
|
2021-03-21 11:45:52 +00:00
|
|
|
- name: Install uefi grub
|
2021-03-18 21:35:44 +00:00
|
|
|
command: arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
|
2021-03-21 11:45:52 +00:00
|
|
|
when: provissionning_UEFI_Enable == True
|
|
|
|
|
|
|
|
- name: Install legacy grub
|
|
|
|
command: "arch-chroot /mnt grub-install {{ item.0.device }} "
|
|
|
|
loop: '{{ mount_table|subelements("settings") }}'
|
2022-09-12 19:37:29 +00:00
|
|
|
when: item.1.mountpath == "/mnt/boot" and provissionning_UEFI_Enable == False
|
|
|
|
|
2021-03-21 11:45:52 +00:00
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: Create grub config
|
|
|
|
command: arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
|
2021-03-21 11:45:52 +00:00
|
|
|
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: Remove root SSH access
|
|
|
|
become: yes
|
|
|
|
lineinfile:
|
|
|
|
dest: /mnt/etc/ssh/sshd_config
|
|
|
|
regexp: "^PermitRootLogin"
|
|
|
|
line: "PermitRootLogin yes"
|
|
|
|
state: present
|
2021-03-21 11:45:52 +00:00
|
|
|
- name: change root password
|
2021-03-21 18:11:25 +00:00
|
|
|
shell:
|
|
|
|
cmd: "echo 'root:{{ vault_default_root | password_hash('sha512')}}' |arch-chroot /mnt chpasswd -e"
|
2021-03-21 11:45:52 +00:00
|
|
|
when: vault_default_root is defined
|
2021-03-18 21:35:44 +00:00
|
|
|
- name: Reboot
|
|
|
|
reboot:
|
2021-03-21 18:11:25 +00:00
|
|
|
msg: reboot in new system
|
|
|
|
reboot_timeout: 60
|
|
|
|
ignore_errors: yes
|
|
|
|
|