From 65eb7c0701e4caa6da28f6f64a504bf8ef86f527 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Thu, 3 Mar 2022 20:17:08 +0100 Subject: [PATCH] Start adding role libvirt --- configs.yml | 13 ------------- playbook.yml | 1 + roles/libvirt/meta/main.yml | 3 +++ roles/libvirt/tasks/main.yml | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 roles/libvirt/meta/main.yml create mode 100644 roles/libvirt/tasks/main.yml diff --git a/configs.yml b/configs.yml index c5062f6..0a5904c 100644 --- a/configs.yml +++ b/configs.yml @@ -119,19 +119,6 @@ gaming: - lib32-vulkan-icd-loader libvirt: - - install: - arch: - - libvirt - - iptables-nft - - dnsmasq - - dmidecode - - virt-install - - virt-viewer - - qemu-headless - - run: - - sudo usermod -aG libvirt "${USER}" - - run: - - 'grep "libvirt libvirt_guest" /etc/nsswitch.conf >/dev/null 2>&1 || sudo sed -i -E "s/^hosts: (.+)/hosts: libvirt libvirt_guest \1/" /etc/nsswitch.conf' - run: - sudo systemctl start libvirtd.service && sudo systemctl enable libvirtd.service - run: diff --git a/playbook.yml b/playbook.yml index d9d46ac..d02fa4b 100644 --- a/playbook.yml +++ b/playbook.yml @@ -26,3 +26,4 @@ - { role: rust, tags: rust } - { role: protonvpn, tags: protonvpn } - { role: repos, tags: repos } + - { role: libvirt, tags: libvirt } diff --git a/roles/libvirt/meta/main.yml b/roles/libvirt/meta/main.yml new file mode 100644 index 0000000..edef5f0 --- /dev/null +++ b/roles/libvirt/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - role: check-sudo diff --git a/roles/libvirt/tasks/main.yml b/roles/libvirt/tasks/main.yml new file mode 100644 index 0000000..828594a --- /dev/null +++ b/roles/libvirt/tasks/main.yml @@ -0,0 +1,33 @@ +--- +- fail: + when: ansible_distribution != 'Archlinux' + +- name: Install packages (Archlinux) + become: true + pacman: + name: + - libvirt + - iptables-nft + - dnsmasq + - dmidecode + - virt-install + - virt-viewer + - qemu-headless + when: ansible_distribution == 'Archlinux' + +- name: Add user to libvirt group + user: + name: "{{ ansible_facts['env']['USER'] }}" + append: yes + groups: libvirt + +- name: Check if "libvirt libvirt_guest" is in /etc/nsswitch.conf + become: true + # TODO: this keeps adding the line over and over again + lineinfile: + path: /etc/nsswitch.conf + regexp: '^hosts: (.+)' + line: 'hosts: libvirt libvirt_guest \1' + state: present + backrefs: true + backup: true