From 3fbdcc0a516b12831aae133874fdce6126de76e4 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Wed, 3 May 2023 21:13:44 +0200 Subject: [PATCH] Move from docker to qemu --- .gitattributes | 1 + .gitignore | 2 ++ ansible.cfg | 2 +- docker/Dockerfile | 10 ---------- docker/start | 3 --- init.sh | 6 ------ prepare_test_env.sh | 19 +++++++++++++++++++ run.sh | 4 ++++ work/base.qcow2 | 3 +++ .../inventory.yaml.sample | 2 +- 10 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitignore delete mode 100644 docker/Dockerfile delete mode 100755 docker/start delete mode 100755 init.sh create mode 100755 prepare_test_env.sh create mode 100755 run.sh create mode 100644 work/base.qcow2 rename docker/inventory.yaml => work/inventory.yaml.sample (77%) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8ab0810 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.qcow2 filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1df46bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +work/image.qcow2 +work/inventory.yaml \ No newline at end of file diff --git a/ansible.cfg b/ansible.cfg index 0ca9d49..8c48cf9 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,4 +1,4 @@ [defaults] -inventory = docker/inventory.yaml +inventory = work/inventory.yaml retry_files_enabled = false interpreter_python = auto_silent \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index f474be0..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM fedora:38 - -RUN dnf install openssh-server -y -RUN ssh-keygen -A -v - -RUN useradd -m -G wheel test -RUN echo 'test:test' | chpasswd - -EXPOSE 22 -CMD ["/usr/sbin/sshd", "-D", "-o", "ListenAddress=0.0.0.0"] \ No newline at end of file diff --git a/docker/start b/docker/start deleted file mode 100755 index b1b9a02..0000000 --- a/docker/start +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -docker build -t ansible_test:latest docker/ -docker run --rm -d --name ansible_test --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw -v $HOME/.ssh/id_rsa.pub:/home/test/.ssh/authorized_keys:ro -p 1022:22 --cgroupns=host ansible_test:latest \ No newline at end of file diff --git a/init.sh b/init.sh deleted file mode 100755 index 1e798d1..0000000 --- a/init.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# Must be run as sudo - -cp ./firewall /etc/init.d/firewall -chmod +x /etc/init.d/firewall -update-rc.d firewall defaults diff --git a/prepare_test_env.sh b/prepare_test_env.sh new file mode 100755 index 0000000..771d157 --- /dev/null +++ b/prepare_test_env.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +#echo "DOWNLOAD FEDORA IMAGE" +#mkdir -p work +#wget --show-progress -nc -c -O work/image.qcow2 https://download.fedoraproject.org/pub/fedora/linux/releases/38/Server/x86_64/images/Fedora-Server-KVM-38-1.6.x86_64.qcow2 + +#echo "PREPARE IMG" +#qemu-img resize work/image.qcow2 30G + +echo "COPY BASE IMG" +cp work/base.qcow2 work/image.qcow2 + +sudo virt-install --name FedoraServer \ + --memory 8192 --cpu host --vcpus 4 --graphics none \ + --os-variant fedora-unknown \ + --import \ + --disk work/image.qcow2,format=qcow2,bus=virtio \ + --network type=direct,source=enp8s0,source_mode=bridge,model=virtio \ + --network bridge=virbr0,model=virtio diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..1403036 --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "START VM" +sudo virsh --connect qemu:///system start FedoraServer --console \ No newline at end of file diff --git a/work/base.qcow2 b/work/base.qcow2 new file mode 100644 index 0000000..5f91e76 --- /dev/null +++ b/work/base.qcow2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7bf9670c300ef151defdef9976ab063123e6314ee43f338030f8da046e15572 +size 1052180480 diff --git a/docker/inventory.yaml b/work/inventory.yaml.sample similarity index 77% rename from docker/inventory.yaml rename to work/inventory.yaml.sample index a6234d0..a6277d7 100644 --- a/docker/inventory.yaml +++ b/work/inventory.yaml.sample @@ -3,4 +3,4 @@ servers: localhost: ansible_connection: ssh ansible_user: test - ansible_port: 1022 + ansible_port: 22