This commit is contained in:
emdee 2023-12-30 22:09:49 +00:00
parent f11ab239af
commit 94c76b2e4b
30 changed files with 176 additions and 326 deletions

View file

@ -1,182 +0,0 @@
# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-
---
- name: "DEBUG: ansible-gentoo_install local"
debug:
verbosity: 0
msg: "DEBUG: ansible-gentoo_install local BOX_NBD_DEV={{BOX_NBD_DEV}}"
check_mode: no
- assert:
that:
- "'{{BOX_NBD_DEV}}' != ''"
when: ansible_connection in ['local', 'chroot']
- set_fact:
AGI_use_local_kernel: true
when:
- ansible_distribution == 'Gentoo' or BOX_GENTOO_FROM_MP not in ['/', '']
- set_fact:
AGI_PROXY_MODE: "{{PROXY_MODE|default('')}}"
when:
- PROXY_MODE|default('') != ''
check_mode: no
- set_fact:
AGI_PROXY_MODE: "{{BOX_PROXY_MODE|default('')}}"
when:
- AGI_PROXY_MODE == ''
check_mode: no
- block:
- name: check for mounted disk
shell: |
grep '/dev/{{AGI_NBD_DEV}}' /proc/mounts && exit 0
ps ax | grep -v grep | \
grep "qemu-nbd.*/dev/nbd.*{{BOX_NBD_BASE_QCOW}}" && \
echo WARN looks like theres an active nbd mount of \
"${BOX_NBD_BASE_QCOW}" && exit 1
exit 2
failed_when: false
changed_when: false
register: check_mounted_disk
check_mode: no
- name: partition if disk not mounted
fail:
msg: "looks like theres an active nbd mount of {{BOX_NBD_BASE_QCOW}}"
when:
- check_mounted_disk.rc == 1
check_mode: no
- name: partition if disk not mounted or active
include: disk.yml
when:
- check_mounted_disk.rc > 1
check_mode: no
- name: mount root partition
mount:
name: "{{AGI_NBD_MP}}"
src: "{{ AGI_install_disk }}p3"
fstype: ext4
state: mounted
check_mode: false
- name: create /boot mountpoint
file:
path: "{{AGI_NBD_MP}}/boot"
state: directory
check_mode: false
- name: mount boot partition
mount:
name: "{{AGI_NBD_MP}}/boot"
src: "{{ AGI_install_disk }}p1"
fstype: ext2
state: mounted
check_mode: false
- name: mount distfiles
delegate_to: localhost
shell: |
[ -d "{{MOUNT_GENTOO_DISTFILES_ARCHIVES}}" ] || exit 1
grep {{MOUNT_GENTOO_DISTFILES_ARCHIVES}} /proc/mounts && exit 0
[ -d {{AGI_NBD_MP}}/usr/portage/ ] || exit 0
[ -d {{AGI_NBD_MP}}/usr/portage/distfiles ] || mkdir {{AGI_NBD_MP}}/usr/portage/distfiles
mount --bind {{MOUNT_GENTOO_DISTFILES_ARCHIVES}} {{AGI_NBD_MP}}/usr/portage/distfiles
when:
- "MOUNT_GENTOO_DISTFILES_ARCHIVES != ''"
- "AGI_NBD_MP != ''"
- false # let the tester take care of this
- include: tarball.yml
- include: copy.yml
when: AGI_use_local_kernel
- include: chroot.yml
delegate_to: localhost
when: ansible_connection in ['chroot', 'local'] # libvirt?
- block:
- name: check chroot wrapper installed
shell: |
[ -x /var/tmp/chroot_wrapper.sh ] || exit 1
df /mnt/gentoo || exit 2
/var/tmp/chroot_wrapper.sh df | grep /mnt/gentoo && exit 4
exit 0
register: chroot_out
check_mode: false
- name: enable chroot wrapper
set_fact:
ansible_shell_executable: /var/tmp/chroot_wrapper.sh
old_ansible_python_interpreter: "{{ansible_python_interpreter}}"
ansible_python_interpreter: "/usr/bin/python3"
check_mode: false
when: ansible_connection in ['local']
- block:
- include: portage.yml
- include: misc.yml
- include: network.yml
- include: kernel.yml
when: not AGI_use_local_kernel
- include: bootloader.yml
- include: daemons.yml
# - include: finish.yml
check_mode: false
when:
- "ansible_connection in ['chroot'] or chroot_out.rc|default(1) == 0"
rescue:
- debug:
msg: "ERROR: "
- name: disable chroot wrapper
set_fact:
ansible_shell_executable: /bin/sh
ansible_python_interpreter: "{{old_ansible_python_interpreter}}"
when:
- "ansible_connection in ['local'] and chroot_out.rc|default(1) == 0"
check_mode: false
- name: unmount filesystems
mount:
name: "{{AGI_NBD_MP}}/{{ item }}"
state: unmounted
with_items:
- proc
- sys
- dev/pts
- dev/shm
- dev
- boot
- ''
loop_control:
label: "{{AGI_NBD_MP}}/{{ item }}"
when:
- "ansible_connection in ['local'] and chroot_out.rc|default(1) == 0"
- false # leave it mounted for testing
- name: dismount any other mounts
shell: |
if [ -z "{{MOUNT_GENTOO_DISTFILES_ARCHIVES}}" ] && \
[ -d "{{MOUNT_GENTOO_DISTFILES_ARCHIVES}}" ] && \
grep {{MOUNT_GENTOO_DISTFILES_ARCHIVES}} /proc/mounts ; then
umount {{MOUNT_GENTOO_DISTFILES_ARCHIVES}}
fi
df -a | grep "{{AGI_NBD_MP}}" | sed -e 's/.* //' | tac | while read elt;do
umount $elt
done
when:
- "ansible_connection in ['chroot'] or chroot_out.rc|default(1) == 0"
- false # leave it mounted for testing

View file

@ -1 +0,0 @@
root@pentoo.152064:1703733868

View file

@ -100,7 +100,7 @@
EOF
bash /etc/rc.local
ignore_errors: true
- name: rc-update add bootlogd boot
shell: |
rc-update | grep -q 'bootlogd .* boot' || \

View file

@ -4,7 +4,7 @@
debug:
verbosity: 1
msg: "DEBUG: ansible-gentoo_install chroot.yml"
- name: test we are NOT in the chroot
shell: |
df | grep "{{AGI_NBD_MP}}" || exit 1
@ -15,7 +15,7 @@
exit 4
[ -d "{{AGI_GENTOO_FROM_MP}}" ] || exit 5
check_mode: false
- name: copy resolv.conf into chroot
copy:
src: /etc/resolv.conf

View file

@ -4,7 +4,7 @@
debug:
verbosity: 1
msg: "DEBUG: ansible-gentoo_install copy.yml"
- name: test we are NOT in the chroot
shell: |
df | grep "{{AGI_NBD_MP}}" || exit 1
@ -15,7 +15,7 @@
exit 4
[ -d "{{AGI_GENTOO_FROM_MP}}" ] || exit 5
check_mode: false
- name: install to mp from source
delegate_to: localhost
shell: |
@ -33,7 +33,7 @@
echo linux
register: kernel_out
check_mode: false
- name: copy kernel sources
copy:
src: "{{AGI_GENTOO_FROM_MP}}/usr/src/{{kernel_out.stdout}}"
@ -44,7 +44,7 @@
- kernel_out.rc|default(1) == 0
- AGI_use_local_kernel
- false # dunno where it went to
- name: resolve kver
shell: |
kernel="{{kernel_out.stdout}}"
@ -62,7 +62,7 @@
check_mode: false
when:
- kver_out.rc|default(1) == 0
- name: resolve vmlinux
shell: |
kver="{{kver_out.stdout}}"
@ -71,7 +71,7 @@
check_mode: false
when:
- kver_out.rc|default(1) == 0
- name: copy kernel vmlinux
copy:
src: "{{AGI_GENTOO_FROM_MP}}{{vmlinux_out.stdout}}"
@ -89,7 +89,7 @@
check_mode: false
when:
- kver_out.rc|default(1) == 0
- name: copy kernel vmlinux
copy:
src: "{{AGI_GENTOO_FROM_MP}}{{ramfs_out.stdout}}"
@ -110,5 +110,5 @@
[ -f "{{AGI_NBD_MP}}/{{file}}" ] && continue
cp -np "$file" "{{AGI_NBD_MP}}/{{file}}"
done
# dracut

View file

@ -4,7 +4,7 @@
debug:
verbosity: 1
msg: "DEBUG: ansible-gentoo_install daemons"
- name: test we are in the chroot
shell: |
df | grep {{AGI_NBD_MP}} && exit 1

View file

@ -4,7 +4,7 @@
debug:
verbosity: 1
msg: "DEBUG: ansible-gentoo_install disk.yml"
- name: test we are NOT in the chroot
shell: |
grep '/dev/{{AGI_NBD_DEV}}' /proc/mounts && exit 1
@ -13,29 +13,33 @@
[ "{{ansible_distribution}}" == 'Gentoo' ] || \
( {{AGI_GENTOO_FROM_MP}} != '' && '{{AGI_GENTOO_FROM_MP}}' != '/' ) || \
exit 4
l [ -d "{{AGI_GENTOO_FROM_MP}}" ] || exit 5
[ -d "{{AGI_GENTOO_FROM_MP}}" ] || exit 5
check_mode: false
- block:
- name: create disklabel
command: parted -s {{ AGI_install_disk }} mklabel {{ AGI_install_disklabel }}
register: disklabel_out
# stderr: 'Warning: Error fsyncing/closing /dev/nbd1: Input/output error'
failed_when: false
- name: disklabel_out
debug:
var: disklabel_out
# you can get into a wierd state with /dev/nbd - partprobe reports
# Error: Partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64 on /dev/nbd3 have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
# and the same thing on all of the rest of your disks! All untrue
# but the qemu -d /dev/nbd1 command will fail silently if busy
when: disklabel_out.rc != 0
- name: This is fatal - you must reboot
fail:
msg: "This is fatal - you must reboot. {{disklabel_out.stderr}}"
when:
- disklabel_out.rc == 1
check_mode: no
# We need to leave a small gap at the beginning of the disk, or grub won't be
# able to install to the MBR
- name: create boot partition
@ -43,56 +47,60 @@ l [ -d "{{AGI_GENTOO_FROM_MP}}" ] || exit 5
parted -s {{ AGI_install_disk }} mkpart primary ext2 1M 200M
args:
creates: "{{ AGI_install_disk }}p1"
- name: mark boot partition as active
shell: |
parted -s {{ AGI_install_disk }} set 1 boot on
- name: create swap partition
shell: |
parted -s {{ AGI_install_disk }} -- mkpart primary linux-swap 201M 2200M
args:
creates: "{{ AGI_install_disk }}p2"
- name: create root partition
shell: |
parted -s {{ AGI_install_disk }} -- mkpart primary ext4 2201M 20070M
args:
creates: "{{ AGI_install_disk }}p3"
- name: format boot partition
filesystem: dev={{ AGI_install_disk }}p1 fstype=ext2 force=yes
check_mode: false
when: not ansible_check_mode
- name: format swap partition
filesystem: dev={{ AGI_install_disk }}p2 fstype=swap force=yes
check_mode: false
when: false
- name: format root partition
filesystem: dev={{ AGI_install_disk }}p3 fstype=ext4 force=yes
check_mode: false
when: not ansible_check_mode
when: false
- block:
shell: |
sfdisk {{ AGI_install_disk }} << EOF
label: dos
label-id: 0x14a8b958
device: {{ AGI_install_disk }}
unit: sectors
sector-size: 512
{{ AGI_install_disk }}p1 : start= 2048, size= 819200, type=83, bootable
{{ AGI_install_disk }}p2 : start= 821248, size= 4096000, type=82
{{ AGI_install_disk }}p3 : start= 4917248, size= 37025792, type=83
EOF
mke2fs {{ AGI_install_disk }}p1
mke2fs {{ AGI_install_disk }}p3
- name: create disk partitions
shell: |
sfdisk {{ AGI_install_disk }} << EOF
label: dos
label-id: 0x14a8b958
device: {{ AGI_install_disk }}
unit: sectors
sector-size: 512
{{ AGI_install_disk }}p1 : start= 2048, size= 819200, type=83, bootable
{{ AGI_install_disk }}p2 : start= 821248, size= 4096000, type=82
{{ AGI_install_disk }}p3 : start= 4917248, size= 37025792, type=83
EOF
mke2fs {{ AGI_install_disk }}p1
mke2fs {{ AGI_install_disk }}p3
when: true
- name: label partitions
shell: |
e2label {{ AGI_install_disk }}p3 root

View file

@ -26,7 +26,7 @@
grep /mnt/gentoo/ /proc/mounts|tac|while read a b c ;do sudo umount $b;done
# leave this to be done
grep nbd /proc/mounts || true
- name: reboot
command: reboot
async: 0

View file

@ -4,7 +4,7 @@
debug:
verbosity: 1
msg: "DEBUG: ansible-gentoo_install kernel"
- name: test we are in the chroot
shell: |
df | grep /mnt/gentoo && exit 1
@ -28,4 +28,4 @@
args:
creates: /boot/kernel-genkernel-*

View file

@ -19,7 +19,7 @@
- set_fact:
AGI_PROXY_MODE: "{{PROXY_MODE|default('')}}"
when:
- PROXY_MODE|default('') != ''
- PROXY_MODE|default('') != ''
check_mode: no
- set_fact:
@ -29,7 +29,7 @@
check_mode: no
- block:
- name: check for mounted disk
shell: |
grep '/dev/{{AGI_NBD_DEV}}' /proc/mounts && exit 0
@ -42,20 +42,20 @@
changed_when: false
register: check_mounted_disk
check_mode: no
- name: partition if disk not mounted
fail:
msg: "looks like theres an active nbd mount of {{BOX_NBD_BASE_QCOW}}"
when:
- check_mounted_disk.rc == 1
check_mode: no
- name: partition if disk not mounted or active
include: disk.yml
when:
- check_mounted_disk.rc > 1
check_mode: no
- name: mount root partition
mount:
name: "{{AGI_NBD_MP}}"
@ -63,13 +63,13 @@
fstype: ext4
state: mounted
check_mode: false
- name: create /boot mountpoint
file:
path: "{{AGI_NBD_MP}}/boot"
state: directory
check_mode: false
- name: mount boot partition
mount:
name: "{{AGI_NBD_MP}}/boot"
@ -90,7 +90,7 @@
- "MOUNT_GENTOO_DISTFILES_ARCHIVES != ''"
- "AGI_NBD_MP != ''"
- false # let the tester take care of this
- include: tarball.yml
- include: copy.yml
when: AGI_use_local_kernel
@ -100,7 +100,7 @@
when: ansible_connection in ['chroot', 'local'] # libvirt?
- block:
- name: check chroot wrapper installed
shell: |
[ -x /var/tmp/chroot_wrapper.sh ] || exit 1
@ -109,7 +109,7 @@
exit 0
register: chroot_out
check_mode: false
- name: enable chroot wrapper
set_fact:
ansible_shell_executable: /var/tmp/chroot_wrapper.sh
@ -118,14 +118,14 @@
check_mode: false
when: ansible_connection in ['local']
- block:
- include: portage.yml
- include: misc.yml
- include: network.yml
- include: kernel.yml
when: not AGI_use_local_kernel
@ -140,7 +140,7 @@
rescue:
- debug:
msg: "ERROR: "
- name: disable chroot wrapper
set_fact:
ansible_shell_executable: /bin/sh

View file

@ -15,7 +15,7 @@
when:
- "'ansible-gentoo_install' in ROLES"
- ansible_check_mode is true
- name: look for nbd partitions
shell: |
grep nbd /proc/partitions | head -1|sed -e 's/.* //'
@ -46,7 +46,7 @@
ignore_errors: true
- block:
- name: set AGI_gentooimgr_configs
set_fact:
AGI_gentooimgr_configs: "{{gentooimgr_out.stdout}}/configs"

View file

@ -97,7 +97,7 @@
mode: '0640'
- block:
- name: make symlinks
shell: |
{% for elt in AGI_bootstrap_pkgs %}

View file

@ -39,7 +39,7 @@
- name: install portage tree snapshot
command: emerge-webrsync
when: false
#- name: update portage tree
# command: emerge --sync

View file

@ -5,7 +5,7 @@
debug:
verbosity: 1
msg: "DEBUG: ansible-gentoo_install tarball"
- name: test we are NOT in the chroot
shell: |
[ -n "{{AGI_NBD_MP}}" ] || exit 2
@ -52,7 +52,7 @@
prefix=$(echo $filename | sed -e "s/$suffix//" );
echo $filename
register: tarball_out
- set_fact:
latest_stage_tarball_url_suffix: "{{ ( latest_stage.content.splitlines() | reject('match', '#') | first ).split(' ')[0] }}"
latest_stage_tarball: "{{ ( latest_stage.content.splitlines() | reject('match', '#') | first ).split(' ')[0].split('/')[1] }}"
@ -68,7 +68,7 @@
when:
- not ansible_check_mode
- tarball_out.rc|default(1) == 0
- name: fetch latest stage tarball
environment: "{{proxy_env}}"
delegate_to: localhost
@ -95,7 +95,7 @@
sha256sum "{{ latest_stage_tarball }}.sha256"
when:
- not ansible_check_mode
- name: extract stage tarball
unarchive:
src: "{{AGI_NBD_FILES}}/{{ latest_stage_tarball }}"