From 1d1b2fff42066a4dff1a5c554eb42905a373dd5a Mon Sep 17 00:00:00 2001 From: Sandwich Date: Mon, 28 Oct 2024 20:26:15 +0100 Subject: [PATCH] Fix connection DNS resolving inside chroot --- roles/bootstrap/tasks/main.yml | 8 +++++--- roles/virtualization/tasks/libvirt.yml | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/roles/bootstrap/tasks/main.yml b/roles/bootstrap/tasks/main.yml index ea26b3e..73e0f38 100644 --- a/roles/bootstrap/tasks/main.yml +++ b/roles/bootstrap/tasks/main.yml @@ -33,6 +33,7 @@ - | debootstrap --include={{ role_packages[os].base | join(',') }} {{ 'mantic' if os == 'ubuntu' else 'jammy' }} \ /mnt http://archive.ubuntu.com/ubuntu/ + - ln -sf /run/systemd/resolve/resolv.conf /mnt/etc/resolv.conf - arch-chroot /mnt sed -i '1s|$| universe|' /etc/apt/sources.list - arch-chroot /mnt apt update -y - arch-chroot /mnt apt install -y {{ role_packages[os].extra | join(' ') }} @@ -44,7 +45,7 @@ register: result with_items: - dnf --releasever=9 --best --repo=alma-baseos --installroot=/mnt --setopt=install_weak_deps=False groupinstall -y base core - - echo "nameserver 1.0.0.1" > /mnt/etc/resolv.conf + - ln -sf /run/systemd/resolve/resolv.conf /mnt/etc/resolv.conf - arch-chroot /mnt dnf --releasever=9 --setopt=install_weak_deps=False install -y {{ role_packages.almalinux | join(' ') }} - name: Bootstrap Fedora 40 @@ -56,6 +57,7 @@ - | dnf --releasever=40 --best --repo=fedora --repo=fedora-updates \ --installroot=/mnt --setopt=install_weak_deps=False groupinstall -y critical-path-base core + - ln -sf /run/systemd/resolve/resolv.conf /mnt/etc/resolv.conf - arch-chroot /mnt dnf --releasever=40 --setopt=install_weak_deps=False install -y {{ role_packages.fedora | join(' ') }} - arch-chroot /mnt dnf reinstall -y kernel-core @@ -66,7 +68,7 @@ register: result with_items: - dnf --releasever=9 --best --repo=rocky-baseos --installroot=/mnt --setopt=install_weak_deps=False groupinstall -y base core - - echo "nameserver 1.0.0.1" > /mnt/etc/resolv.conf + - ln -sf /run/systemd/resolve/resolv.conf /mnt/etc/resolv.conf - arch-chroot /mnt dnf --releasever=9 --setopt=install_weak_deps=False install -y {{ role_packages.rocky | join(' ') }} - name: Bootstrap RHEL System @@ -76,5 +78,5 @@ register: result with_items: - dnf --releasever={{ '8' if os == 'rhel8' else '9' }} --installroot=/mnt --setopt=install_weak_deps=False groupinstall -y base core - - echo 'nameserver 1.0.0.1' > /mnt/etc/resolv.conf + - ln -sf /run/systemd/resolve/resolv.conf /mnt/etc/resolv.conf - arch-chroot /mnt dnf --releasever={{ '8' if os == 'rhel8' else '9' }} --setopt=install_weak_deps=False install -y {{ role_packages[os] | join(' ') }} diff --git a/roles/virtualization/tasks/libvirt.yml b/roles/virtualization/tasks/libvirt.yml index 458d566..0a41938 100644 --- a/roles/virtualization/tasks/libvirt.yml +++ b/roles/virtualization/tasks/libvirt.yml @@ -30,9 +30,9 @@ - name: Create cloud-init disk delegate_to: localhost - ansible.builtin.command: cloud-localds - {{ vm_path | default('/var/lib/libvirt/images/') }} - {{ hostname }}-cloudinit.iso /tmp/cloud-user-data-{{ hostname }}.yml + ansible.builtin.shell: | + cloud-localds {{ vm_path | default('/var/lib/libvirt/images/') }}\ + {{ hostname }}-cloudinit.iso /tmp/cloud-user-data-{{ hostname }}.yml \ -N /tmp/cloud-network-config-{{ hostname }}.yml changed_when: result.rc == 0 register: result