ansible-arch-provissionning/tasks/main.yml

117 lines
3.2 KiB
YAML
Raw Normal View History

2021-03-14 12:41:46 +00:00
---
2021-03-18 21:35:44 +00:00
# tasks file for ansible-arch-provissionninga
#
- name: debug
debug:
var: item
loop: '{{ partition_table|subelements("settings") }}'
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 }}"
label: gpt
number: "{{ item.1.number }}"
part_start: "{{ item.1.part_start | default('0%') }}"
part_end: "{{ item.1.part_end | default('100%') }}"
name: "{{ item.1.name }}"
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:
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:
- name: Install grub
command: arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
- name: Create grub config
command: arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
- name: Remove root SSH access
become: yes
lineinfile:
dest: /mnt/etc/ssh/sshd_config
regexp: "^PermitRootLogin"
line: "PermitRootLogin yes"
state: present
- name: Reboot
reboot:
connect_timeout: 1
reboot_timeout: 1
failed_when: false