added
This commit is contained in:
parent
eaf6ffdbef
commit
c417a6f3f9
29 changed files with 16625 additions and 608 deletions
|
@ -1,183 +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
|
||||
|
||||
- include: tarball.yml
|
||||
- include: copy.yml
|
||||
when: AGI_use_local_kernel
|
||||
|
||||
- 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 != ''"
|
||||
|
||||
- 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 /bin/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 (ansible_connection in ['local'] or and chroot_out.rc|default(1) == 0)"
|
||||
rescue:
|
||||
- debug:
|
||||
msg: "ERROR: error during chroot execution"
|
||||
|
||||
- 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
|
||||
base_chroot_unbind.bash "{{AGI_NBD_MP}}"
|
||||
when:
|
||||
- "ansible_connection in ['chroot'] or chroot_out.rc|default(1) == 0"
|
||||
- false # leave it mounted for testing
|
|
@ -39,12 +39,12 @@
|
|||
- name: copy kernel sources
|
||||
copy:
|
||||
src: "{{AGI_GENTOO_FROM_MP}}/usr/src/{{kernel_out.stdout}}"
|
||||
dest: "{{AGI_NBD_MP}}/usr/src"
|
||||
dest: "{{AGI_NBD_MP}}/usr/src/{{kernel_out.stdout}}"
|
||||
remote_src: no
|
||||
creates: "{{AGI_NBD_MP}}/usr/src/{{kernel_out.stdout}}"
|
||||
when:
|
||||
- kernel_out.rc|default(1) == 0
|
||||
- AGI_use_local_kernel
|
||||
- false
|
||||
|
||||
- name: resolve kver
|
||||
shell: |
|
||||
|
@ -99,6 +99,8 @@
|
|||
when:
|
||||
- AGI_use_local_kernel
|
||||
- ramfs_out.rc|default(1) == 0
|
||||
- false
|
||||
ignore_errors: true
|
||||
|
||||
- name: make directories
|
||||
shell: |
|
||||
|
@ -111,6 +113,6 @@
|
|||
[ -f "{{AGI_NBD_MP}}/$file" ] && continue
|
||||
cp -np "$file" "{{AGI_NBD_MP}}/$file"
|
||||
done
|
||||
ignore_errors: false
|
||||
ignore_errors: true
|
||||
|
||||
# dracut
|
||||
|
|
|
@ -32,12 +32,19 @@
|
|||
|
||||
- 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
|
||||
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
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
register: check_mounted_disk
|
||||
|
@ -45,15 +52,15 @@
|
|||
|
||||
- name: partition if disk not mounted
|
||||
fail:
|
||||
msg: "looks like theres an active nbd mount of {{BOX_NBD_BASE_QCOW}}"
|
||||
msg: "make and nbd mount {{BOX_NBD_BASE_QCOW}}"
|
||||
when:
|
||||
- check_mounted_disk.rc == 1
|
||||
- check_mounted_disk.rc in [2, 1]
|
||||
check_mode: no
|
||||
|
||||
- name: partition if disk not mounted or active
|
||||
include: disk.yml
|
||||
when:
|
||||
- check_mounted_disk.rc > 1
|
||||
- check_mounted_disk.rc > 2
|
||||
check_mode: no
|
||||
|
||||
- name: mount root partition
|
||||
|
|
|
@ -52,6 +52,8 @@
|
|||
fi
|
||||
if ! grep -q "{{BOX_NBD_DEV}}" /proc/partitions ; then
|
||||
echo ERROR: not mounted BOX_NBD_DEV="{{BOX_NBD_DEV}}" - use qemu-nbd
|
||||
echo qemu-img create -f qcow2 /a/tmp/GentooImgr/gentoo.qcow2 20G
|
||||
echo qemu-nbd -n -f qcow2 -c /dev/nbd1 /a/tmp/GentooImgr/gentoo.qcow
|
||||
exit 2
|
||||
fi
|
||||
exit 0
|
||||
|
@ -71,19 +73,27 @@
|
|||
fi
|
||||
fi
|
||||
# should operate on json with jq
|
||||
# "imgsize": "20G",
|
||||
# "memory": 4096,
|
||||
# "mountpoint": "/mnt/gentoo",
|
||||
# "imagename": null,
|
||||
# "initsys": "openrc",
|
||||
# "iso": null,
|
||||
# "portage": null,
|
||||
# "stage3": null,
|
||||
# "partition": 1
|
||||
if [ -f "$tofile" ] ; then
|
||||
# "imgsize": "20G",
|
||||
sed -i -e 's@"imgsize": ".*"@"imgsize": "{{BOX_NBD_OVERLAY_GB}}"@' $tofile
|
||||
# "memory": 4096,
|
||||
sed -i -e 's@"memory": ".*"@"imgsize": "{{BOX_NBD_OVERLAY_RAM}}"@' $tofile
|
||||
# "mountpoint": "/mnt/gentoo",
|
||||
sed -i -e 's@"mountpoint": ".*"@"mountpoint": "{{BOX_NBD_MP}}"@' $tofile
|
||||
# "imagename": null,
|
||||
sed -i -e 's@"imagename": ".*"@"imagename": "{{BOX_NBD_OVERLAY_NAME}}"@' $tofile
|
||||
# "initsys": "openrc",
|
||||
sed -i -e 's@"initsys": ".*"@"initsys: "{{BOX_NBD_BASE_PROFILE}}"@' $tofile
|
||||
# "iso": null,
|
||||
# "portage": null,
|
||||
sed -i -e 's@""portage": ".*"@""portage: "{{BOX_NBD_PORTAGE_FILE}}"@' $tofile
|
||||
# "stage3": null,
|
||||
sed -i -e 's@""stage3": ".*"@""stage3: "{{BOX_NBD_STAGE3_FILE}}"@' $tofile
|
||||
# "partition": 1
|
||||
sed -i -e 's@"partition": ".*"@"partition": 3@' $tofile
|
||||
# but this is crucial
|
||||
# "disk": "/dev/sda",
|
||||
sed -i -e 's@"disk": ".*"@"disk": "'{{BOX_NBD_DEV}}'"@' $tofile
|
||||
sed -i -e 's@"disk": ".*"@"disk": "{{BOX_NBD_DEV}}"@' $tofile
|
||||
grep {{BOX_NBD_DEV}} $tofile || exit 4
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue