This commit is contained in:
nora 2024-03-09 22:55:28 +01:00
parent c27807e86f
commit 64cb1dd6df
7 changed files with 39 additions and 5 deletions

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"ansible.python.interpreterPath": "/etc/profiles/per-user/nils/bin/python"
}

6
ansible/debian.yml Normal file
View file

@ -0,0 +1,6 @@
---
- name: Install Debian
hosts: all
become: true
roles:
- update

View file

@ -0,0 +1,6 @@
- name: Update
ansible.builtin.apt:
update_cache: true
- name: Upgrade
ansible.builtin.apt:
upgrade: true

View file

@ -2,8 +2,6 @@
set -eu set -eu
DIR="$(dirname "$(realpath "$0")")"
NAME="$1" NAME="$1"
mkdir -p tmp mkdir -p tmp
@ -33,11 +31,20 @@ virt-install -n "$NAME" \
--import --disk "path=$DISK,bus=virtio" \ --import --disk "path=$DISK,bus=virtio" \
--network network=default,model=virtio \ --network network=default,model=virtio \
--graphics=none --rng /dev/urandom \ --graphics=none --rng /dev/urandom \
"--cloud-init=user-data=$DIR/user-data,meta-data=$meta_data" \ "--cloud-init=user-data=user-data,meta-data=$meta_data" \
--noautoconsole --noautoconsole
rm "$meta_data" rm "$meta_data"
echo "Successfully created $NAME" echo "Successfully created $NAME"
virsh domifaddr "$NAME" until virsh domifaddr "$NAME" | grep ipv4 >/dev/null; do
echo "waiting for VM to start up and get an IP"
sleep 1
done
ip=$(virsh domifaddr "$NAME" | grep ipv4 | awk '{print $4}' | cut -d/ -f1)
echo "IP: $ip"
echo "$ip" >> vm-state/inventory.ini

7
init.sh Normal file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
mkdir -p vm-state
cat >vm-state/inventory-ini <<EOF
[myhosts]
EOF

5
install-vms-ansible.sh Normal file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
ansible-playbook -u chef -i vm-state/inventory.ini ansible/debian.yml

View file

@ -1,3 +1,3 @@
{ pkgs ? import <nixpkgs> { } }: pkgs.mkShell { { pkgs ? import <nixpkgs> { } }: pkgs.mkShell {
packages = with pkgs; [ debootstrap ]; packages = with pkgs; [ debootstrap ansible ansible-lint ];
} }