libvirt_cloud/roles/ansible-gentoo_install/tasks/main.yml

141 lines
5.2 KiB
YAML
Raw Permalink Normal View History

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 nbd_disk ansible_connection"
debug:
2023-12-30 12:01:03 +00:00
verbosity: 0
msg: "DEBUG: ansible-gentoo_install nbd_disk={{ nbd_disk }} AGI_NBD_DISK={{AGI_NBD_DISK}} ansible_connection={{ ansible_connection }}"
2023-12-29 19:40:31 +00:00
check_mode: false
- set_fact:
AGI_target: Gentoo2
- name: look for nbd partitions
shell: |
2023-12-30 12:01:03 +00:00
grep nbd /proc/partitions | head -1|sed -e 's/.* //'
2023-12-29 19:40:31 +00:00
register: nbd_out
failed_when: false
check_mode: false
- name: "include base by-platform vars"
include_vars: "{{item}}.yml"
with_items:
- "Linux"
- "{{ ansible_distribution }}{{ ansible_distribution_major_version }}"
- "target_{{AGI_target}}"
tags: always
- name: find module gentooimgr
shell: |
echo nbd_disk={{ nbd_disk }} ansible_connection={{ ansible_connection }}
echo ansible_distribution={{ansible_distribution}} BOX_GENTOO_FROM_MP={{BOX_GENTOO_FROM_MP}}
2023-12-30 12:01:03 +00:00
[ -d '{{PLAY_ANSIBLE_SRC}}/src/ansible_gentooimgr' ] || exit 1
[ -f '{{PLAY_ANSIBLE_SRC}}/src/ansible_gentooimgr/__init__.py' ] || exit 2
[ -d '{{PLAY_ANSIBLE_SRC}}/src/ansible_gentooimgr/gentooimgr' ] || exit 3
[ -f '{{PLAY_ANSIBLE_SRC}}/src/ansible_gentooimgr/gentooimgr/__init__.py' ] || exit 4
2023-12-29 19:40:31 +00:00
{{ansible_python_interpreter}} \
2023-12-31 03:19:26 +00:00
-c "import os, sys; sys.path.append('{{PLAY_ANSIBLE_SRC}}/src/ansible_gentooimgr'); import gentooimgr; print(os.path.dirname(gentooimgr.__file__))" || exit 5
2023-12-29 19:40:31 +00:00
register: gentooimgr_out
check_mode: false
ignore_errors: true
- block:
2023-12-30 22:09:49 +00:00
2023-12-30 12:01:03 +00:00
- name: set AGI_gentooimgr_configs
set_fact:
2023-12-31 03:19:26 +00:00
AGI_gentooimgr_configs: "{{gentooimgr_out.stdout_lines[-1]}}/configs"
- name: check for a gentooimgr base config
shell: |
if [ -z "{{BOX_NBD_DEV}}" ] ; then
echo ERROR: empty "BOX_NBD_DEV" - define it in hosts.yml
exit 1
fi
if ! grep -q "{{BOX_NBD_DEV}}" /proc/partitions ; then
echo ERROR: not mounted BOX_NBD_DEV="{{BOX_NBD_DEV}}" - use qemu-nbd
2024-01-01 01:04:40 +00:00
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
2023-12-31 03:19:26 +00:00
exit 2
fi
exit 0
- name: make a gentooimgr base config
shell: |
base=base.json
tofile="{{AGI_GENTOOIMGR_CONFIGFILE}}"
todir=`dirname "$tofile"`
[ -d $todir ] || mkdir $todir
if [ ! -f "$tofile" ] ; then
if [ -f "{{AGI_gentooimgr_configs}}/$base" ] ; then
cp -p "{{AGI_gentooimgr_configs}}/$base" "$tofile" || exit 2
else
echo WARN: FNF "{{AGI_gentooimgr_configs}}/$base"
# use base.json
fi
fi
# should operate on json with jq
if [ -f "$tofile" ] ; then
2024-01-01 01:04:40 +00:00
# "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
2023-12-31 03:19:26 +00:00
# but this is crucial
# "disk": "/dev/sda",
2024-01-01 01:04:40 +00:00
sed -i -e 's@"disk": ".*"@"disk": "{{BOX_NBD_DEV}}"@' $tofile
2023-12-31 03:19:26 +00:00
grep {{BOX_NBD_DEV}} $tofile || exit 4
fi
- name: check for library/ansible_gentooimgr.py
shell: |
# find it
[ -f '{{PLAY_ANSIBLE_SRC}}/library/ansible_gentooimgr.py' ] || exit 1
# run it
echo '{}' | \
{{ansible_python_interpreter}} \
'{{PLAY_ANSIBLE_SRC}}/library/ansible_gentooimgr.py' 2>&1| \
grep "Unable to figure out what parameters were passed" && exit 0
echo WARN: ansible_gentooimgr.py BROKEN
2023-12-29 19:40:31 +00:00
2023-12-31 03:19:26 +00:00
- name: ansible_gentooimgr NBD STATUS
2023-12-29 19:40:31 +00:00
ansible_gentooimgr:
action: status
2023-12-30 12:01:03 +00:00
loglevel: "{{BOX_NBD_LOGLEVEL}}"
2023-12-29 19:40:31 +00:00
threads: 1
2024-01-02 02:13:28 +00:00
# base.json - bare filename in configs
config: "{{AGI_GENTOOIMGR_CONFIGFILE}}"
2023-12-30 12:01:03 +00:00
profile: "{{BOX_NBD_BASE_PROFILE}}"
kernel_dir: "{{BOX_NBD_KERNEL_DIR}}"
2023-12-31 03:19:26 +00:00
portage: "{{BOX_NBD_PORTAGE_FILE}}"
stage3: "{{BOX_NBD_STAGE3_FILE }}"
2023-12-30 12:01:03 +00:00
temporary_dir: "{{BOX_NBD_BASE_DIR}}"
2023-12-29 19:40:31 +00:00
download_dir: "{{AGI_NBD_FILES}}"
2023-12-30 12:01:03 +00:00
register: ansible_gentooimgr_out
2023-12-29 19:40:31 +00:00
ignore_errors: true
check_mode: false
2023-12-30 12:01:03 +00:00
- name: "DEBUG: ansible-gentoo_install nbd_disk ansible_connection"
debug:
verbosity: 0
var: ansible_gentooimgr_out
2024-02-02 09:09:08 +00:00
check_mode: false
2023-12-29 19:40:31 +00:00
2024-01-05 11:12:55 +00:00
- name: include_tasks local.yml
include_tasks: local.yml
2023-12-29 19:40:31 +00:00
when:
- ansible_connection in ['chroot', 'local']
2023-12-30 12:01:03 +00:00
- ansible_distribution == 'Gentoo' or BOX_GENTOO_FROM_MP not in ['/', '']
# - nbd_disk|default('') == AGI_NBD_DISK