2023-12-29 19:40:31 +00:00
|
|
|
# -*- 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:
|
2023-12-30 12:01:03 +00:00
|
|
|
- ansible_distribution == 'Gentoo' or BOX_GENTOO_FROM_MP not in ['/', '']
|
2023-12-29 19:40:31 +00:00
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
AGI_PROXY_MODE: "{{PROXY_MODE|default('')}}"
|
|
|
|
when:
|
2023-12-30 22:09:49 +00:00
|
|
|
- PROXY_MODE|default('') != ''
|
2023-12-29 19:40:31 +00:00
|
|
|
check_mode: no
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
AGI_PROXY_MODE: "{{BOX_PROXY_MODE|default('')}}"
|
|
|
|
when:
|
|
|
|
- AGI_PROXY_MODE == ''
|
|
|
|
check_mode: no
|
|
|
|
|
|
|
|
- block:
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- name: check for mounted disk
|
|
|
|
shell: |
|
2024-01-01 01:04:40 +00:00
|
|
|
grep '/dev/{{AGI_NBD_DEV}}p3' /proc/mounts && exit 0
|
|
|
|
if [ ! -f "{{BOX_NBD_BASE_QCOW}}" ] ; then
|
|
|
|
echo ERROR: not created BOX_NBD_DEV="{{BOX_NBD_DEV}}" - use
|
|
|
|
echo qemu-img create -f qcow2 "{{BOX_NBD_BASE_QCOW}}" 20G
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if ! ps ax | grep -v grep | \
|
|
|
|
grep "qemu-nbd.*{{AGI_NBD_DEV}}.*{{BOX_NBD_BASE_QCOW}}" ; then
|
|
|
|
echo ERROR: not mounted BOX_NBD_DEV="{{BOX_NBD_DEV}}" - use
|
|
|
|
echo qemu-nbd -n -f qcow2 -c /dev/nbd1 {{BOX_NBD_BASE_QCOW}}
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
exit 3
|
2023-12-29 19:40:31 +00:00
|
|
|
failed_when: false
|
|
|
|
changed_when: false
|
|
|
|
register: check_mounted_disk
|
|
|
|
check_mode: no
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- name: partition if disk not mounted
|
2023-12-30 12:01:03 +00:00
|
|
|
fail:
|
2024-01-01 01:04:40 +00:00
|
|
|
msg: "make and nbd mount {{BOX_NBD_BASE_QCOW}}"
|
2023-12-30 12:01:03 +00:00
|
|
|
when:
|
2024-01-01 01:04:40 +00:00
|
|
|
- check_mounted_disk.rc in [2, 1]
|
2023-12-30 12:01:03 +00:00
|
|
|
check_mode: no
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-30 12:01:03 +00:00
|
|
|
- name: partition if disk not mounted or active
|
2023-12-29 19:40:31 +00:00
|
|
|
include: disk.yml
|
|
|
|
when:
|
2024-01-01 01:04:40 +00:00
|
|
|
- check_mounted_disk.rc > 2
|
2023-12-29 19:40:31 +00:00
|
|
|
check_mode: no
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- name: mount root partition
|
|
|
|
mount:
|
|
|
|
name: "{{AGI_NBD_MP}}"
|
|
|
|
src: "{{ AGI_install_disk }}p3"
|
|
|
|
fstype: ext4
|
|
|
|
state: mounted
|
|
|
|
check_mode: false
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- name: create /boot mountpoint
|
|
|
|
file:
|
|
|
|
path: "{{AGI_NBD_MP}}/boot"
|
|
|
|
state: directory
|
|
|
|
check_mode: false
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- name: mount boot partition
|
|
|
|
mount:
|
|
|
|
name: "{{AGI_NBD_MP}}/boot"
|
|
|
|
src: "{{ AGI_install_disk }}p1"
|
|
|
|
fstype: ext2
|
|
|
|
state: mounted
|
|
|
|
check_mode: false
|
|
|
|
|
2023-12-31 07:39:01 +00:00
|
|
|
- include: tarball.yml
|
|
|
|
- include: copy.yml
|
|
|
|
when: AGI_use_local_kernel
|
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- 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 != ''"
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- include: chroot.yml
|
|
|
|
|
|
|
|
delegate_to: localhost
|
|
|
|
when: ansible_connection in ['chroot', 'local'] # libvirt?
|
|
|
|
|
|
|
|
- block:
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- name: check chroot wrapper installed
|
|
|
|
shell: |
|
|
|
|
[ -x /var/tmp/chroot_wrapper.sh ] || exit 1
|
|
|
|
df /mnt/gentoo || exit 2
|
2023-12-31 07:39:01 +00:00
|
|
|
/var/tmp/chroot_wrapper.sh /bin/df | grep /mnt/gentoo && exit 4
|
2023-12-29 19:40:31 +00:00
|
|
|
exit 0
|
|
|
|
register: chroot_out
|
|
|
|
check_mode: false
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- 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']
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- block:
|
|
|
|
|
|
|
|
- include: portage.yml
|
|
|
|
- include: misc.yml
|
|
|
|
|
|
|
|
- include: network.yml
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- include: kernel.yml
|
|
|
|
when: not AGI_use_local_kernel
|
|
|
|
|
|
|
|
- include: bootloader.yml
|
|
|
|
- include: daemons.yml
|
|
|
|
|
|
|
|
# - include: finish.yml
|
|
|
|
|
|
|
|
check_mode: false
|
|
|
|
when:
|
2024-01-02 02:13:28 +00:00
|
|
|
- "ansible_connection in ['chroot'] or (ansible_connection in ['local'] and chroot_out.rc|default(1) == 0)"
|
2023-12-29 19:40:31 +00:00
|
|
|
rescue:
|
|
|
|
- debug:
|
2023-12-31 07:39:01 +00:00
|
|
|
msg: "ERROR: error during chroot execution"
|
2023-12-30 22:09:49 +00:00
|
|
|
|
2023-12-29 19:40:31 +00:00
|
|
|
- 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
|
2023-12-31 07:39:01 +00:00
|
|
|
base_chroot_unbind.bash "{{AGI_NBD_MP}}"
|
2023-12-29 19:40:31 +00:00
|
|
|
when:
|
|
|
|
- "ansible_connection in ['chroot'] or chroot_out.rc|default(1) == 0"
|
|
|
|
- false # leave it mounted for testing
|