From f11ab239af383257f742c39bfb617a10b5884d5c Mon Sep 17 00:00:00 2001 From: emdee Date: Sat, 30 Dec 2023 22:04:40 +0000 Subject: [PATCH] updates --- .gitignore | 173 +++++++++++++++++ .../usr/local/src/ansible_gentooimgr.bash | 2 - .../ansible-gentoo_install/tasks/#local.yml# | 182 ++++++++++++++++++ .../ansible-gentoo_install/tasks/.#local.yml | 1 + roles/ansible-gentoo_install/tasks/disk.yml | 122 +++++++----- .../templates/etc/disks/nbd.sfdisk | 9 + 6 files changed, 440 insertions(+), 49 deletions(-) create mode 100644 .gitignore delete mode 100644 overlay/Linux/usr/local/src/ansible_gentooimgr.bash create mode 100644 roles/ansible-gentoo_install/tasks/#local.yml# create mode 120000 roles/ansible-gentoo_install/tasks/.#local.yml create mode 100644 roles/ansible-gentoo_install/templates/etc/disks/nbd.sfdisk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..784e2c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,173 @@ +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +*.diff +*.good +*.bad + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +.pylint.err +.pylint.log +.pylint.out + +*.dst + +*~ +.rsync.sh diff --git a/overlay/Linux/usr/local/src/ansible_gentooimgr.bash b/overlay/Linux/usr/local/src/ansible_gentooimgr.bash deleted file mode 100644 index 13f4793..0000000 --- a/overlay/Linux/usr/local/src/ansible_gentooimgr.bash +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh - diff --git a/roles/ansible-gentoo_install/tasks/#local.yml# b/roles/ansible-gentoo_install/tasks/#local.yml# new file mode 100644 index 0000000..1b774c0 --- /dev/null +++ b/roles/ansible-gentoo_install/tasks/#local.yml# @@ -0,0 +1,182 @@ +# -*- 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 diff --git a/roles/ansible-gentoo_install/tasks/.#local.yml b/roles/ansible-gentoo_install/tasks/.#local.yml new file mode 120000 index 0000000..7523540 --- /dev/null +++ b/roles/ansible-gentoo_install/tasks/.#local.yml @@ -0,0 +1 @@ +root@pentoo.152064:1703733868 \ No newline at end of file diff --git a/roles/ansible-gentoo_install/tasks/disk.yml b/roles/ansible-gentoo_install/tasks/disk.yml index a5cdd35..5ded907 100644 --- a/roles/ansible-gentoo_install/tasks/disk.yml +++ b/roles/ansible-gentoo_install/tasks/disk.yml @@ -11,60 +11,88 @@ [ -n "{{AGI_NBD_MP}}" ] || exit 2 [ -d "{{AGI_NBD_MP}}" ] || exit 3 [ "{{ansible_distribution}}" == 'Gentoo' ] || \ - ( {{AGI_GENTOO_FROM_MP}} != '' && "{{AGI_GENTOO_FROM_MP}}" != '/' ) || \ + ( {{AGI_GENTOO_FROM_MP}} != '' && '{{AGI_GENTOO_FROM_MP}}' != '/' ) || \ exit 4 - [ -d "{{AGI_GENTOO_FROM_MP}}" ] || exit 5 +l [ -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 + - 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 -# 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 - shell: | - 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 + - 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. + - 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 + shell: | + 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 -- name: format root partition - filesystem: dev={{ AGI_install_disk }}p3 fstype=ext4 force=yes - check_mode: false - when: not ansible_check_mode +- 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 + when: true + - name: label partitions shell: | e2label {{ AGI_install_disk }}p3 root diff --git a/roles/ansible-gentoo_install/templates/etc/disks/nbd.sfdisk b/roles/ansible-gentoo_install/templates/etc/disks/nbd.sfdisk new file mode 100644 index 0000000..9098f17 --- /dev/null +++ b/roles/ansible-gentoo_install/templates/etc/disks/nbd.sfdisk @@ -0,0 +1,9 @@ +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