From 7361a3442a321c73161af55dcb3bc8a1aeddf551 Mon Sep 17 00:00:00 2001 From: Antoine Date: Fri, 13 Nov 2020 16:09:22 +0100 Subject: [PATCH] fix : ensX network interface index --- Makefile | 4 ++-- docker-compose.yml | 18 ++++-------------- .../roles/debian-init/defaults/main.yml | 2 +- image/assets/hcl/source-debian.pkr.hcl | 10 +++++++--- image/assets/run-packer.sh | 2 +- run-image.sh | 4 ++-- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index d4f3baa..6b6d3dc 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,10 @@ exec-debian: docker-compose exec debian_packer bash test-debian: - ./run-image.sh debian + ./run-image.sh ./image/assets/output_qcow2/debian_packer.qcow2 test-gentoo: - ./run-image.sh gentoo + ./run-image.sh ./image/assets/output_qcow2/gentoo_packer.qcow2 down: docker-compose down diff --git a/docker-compose.yml b/docker-compose.yml index e7d1a74..ec0cbcf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,6 @@ services: gentoo_packer: image: ${REGISTRY_URL}/${IMAGE_NAME}:${VERSION} privileged: true - network_mode: "host" environment: - SOURCE_NAME=qemu.gentoo - SSH_LIVE_USERNAME=root @@ -16,15 +15,12 @@ services: volumes: - "./image/assets:/packer" - "./image/cache:/packer-cache" - #ports: - # - "5900:5900/udp" - # - "2222:2229" - # - "10082:10082" + ports: + - "5900:5900" debian_packer: image: ${REGISTRY_URL}/${IMAGE_NAME}:${VERSION} privileged: true - network_mode: "host" environment: - SOURCE_NAME=qemu.debian - SSH_LIVE_USERNAME=debian @@ -36,11 +32,5 @@ services: volumes: - "./image/assets:/packer" - "./image/cache:/packer-cache" - #ports: - # - "5900:5900/udp" - # - "2222:2229" - # - "10082:10082" -# entrypoint: "bash -c" -# command: "'while sleep 3600; do :; done'" -# stdin_open: true -# tty: true + ports: + - "5900:5900" diff --git a/image/assets/ansible/roles/debian-init/defaults/main.yml b/image/assets/ansible/roles/debian-init/defaults/main.yml index 5c50719..bfca8e8 100644 --- a/image/assets/ansible/roles/debian-init/defaults/main.yml +++ b/image/assets/ansible/roles/debian-init/defaults/main.yml @@ -5,7 +5,7 @@ grub_timeout: 1 network_config: src: "interfaces.j2" dest: "/etc/network/interfaces" - nic_name: "ens4" + nic_name: "ens3" initial_package: - vim diff --git a/image/assets/hcl/source-debian.pkr.hcl b/image/assets/hcl/source-debian.pkr.hcl index fb7a687..e31f241 100644 --- a/image/assets/hcl/source-debian.pkr.hcl +++ b/image/assets/hcl/source-debian.pkr.hcl @@ -25,20 +25,24 @@ source "qemu" "debian" { http_port_min = 10082 host_port_min = 2229 host_port_max = 2229 + vnc_bind_address = "0.0.0.0" + vnc_port_min = 5900 + vnc_port_max = 5900 iso_checksum = "${var.iso_checksum}" iso_url = "${var.iso_url}" memory = 2048 net_device = "virtio-net" output_directory = "output_qcow2" + // Warning -device order impact network interface naming index ensX qemuargs = [ ["-boot", "b"], - ["-device", "virtio-rng-pci"] + ["-device", "virtio-net,netdev=user.0"], + ["-netdev", "user,id=user.0,hostfwd=tcp::{{ .SSHHostPort }}-:22"], + ["-device", "virtio-rng-pci"], ] shutdown_command = "sudo /sbin/shutdown -hP now" ssh_password = "${var.ssh_password}" ssh_username = "${var.ssh_username}" ssh_wait_timeout = "900m" vm_name = "debian_packer.qcow2" - vnc_port_max = "5900" - vnc_port_min = "5900" } diff --git a/image/assets/run-packer.sh b/image/assets/run-packer.sh index cac24c9..e4137f6 100755 --- a/image/assets/run-packer.sh +++ b/image/assets/run-packer.sh @@ -10,7 +10,7 @@ SSH_PUB=$(cat ./id_rsa_qemu.pub) export PACKER_LOG=1; packer build --only="$SOURCE_NAME" \ -var ssh_username="$SSH_LIVE_USERNAME" \ -var ssh_password="$SSH_LIVE_PASSWORD" \ - -var ansible_extra_vars="$ANSIBLE_EXTRA_VARS ssh_pub=$SSH_PUB" \ + -var ansible_extra_vars="$ANSIBLE_EXTRA_VARS ssh_pub='$SSH_PUB'" \ -var ansible_provisioning_playbook="$ANSIBLE_PLAYBOOK" \ -var iso_checksum="$ISO_CHECKSUM" \ -var iso_url="$ISO_URL" \ diff --git a/run-image.sh b/run-image.sh index f2da73c..53bab35 100755 --- a/run-image.sh +++ b/run-image.sh @@ -1,6 +1,6 @@ #!/bin/bash -# pass debian or gentoo as first parameter +# pass qcow2 image path as first parameter if [ "$#" -lt 1 ]; then exit 1 fi @@ -9,7 +9,7 @@ fi qemu-system-x86_64 \ -boot order=d -m 1024 \ -smp cpus=1,sockets=2,maxcpus=2 \ - -drive "file=./image/assets/output_qcow2/$1_packer.qcow2,format=qcow2,index=1" \ + -drive "file=$1,format=qcow2,index=1" \ -net nic,model=virtio \ -net user,hostfwd=tcp::5556-:22