setup-cockpit/roles/libvirt/tasks/main.yml

70 lines
1.7 KiB
YAML

---
- name: This role only works on Archlinux
ansible.builtin.fail:
when: ansible_facts['distribution'] != 'Archlinux'
- name: Install packages (Archlinux)
become: true
community.general.pacman:
name:
- libvirt
- iptables-nft
- dnsmasq
- dmidecode
- virt-install
- virt-viewer
- qemu-headless
- python-lxml
when: ansible_facts['distribution'] == 'Archlinux'
- name: Add user to libvirt group
become: true
ansible.builtin.user:
name: "{{ ansible_facts['env']['USER'] }}"
append: true
groups: libvirt
- name: Put 'libvirt libvirt_guest' in /etc/nsswitch.conf
become: true
vars:
nsswitch_content: "{{ lookup('file', '/etc/nsswitch.conf') }}"
ansible.builtin.lineinfile:
path: /etc/nsswitch.conf
regexp: '^hosts: (.+)'
line: 'hosts: libvirt libvirt_guest \1'
state: present
backrefs: true
backup: true
when: "'libvirt libvirt_guest' not in nsswitch_content"
- name: Create session pool dir
ansible.builtin.file:
path: "{{ pool_path }}"
state: directory
mode: 0755
- name: Define session pool
community.libvirt.virt_pool:
command: define
name: "{{ pool_name }}"
uri: "qemu:///session"
xml: "{{ lookup('template', 'libvirt-pool.xml.j2') }}"
- name: Start session pool
community.libvirt.virt_pool:
state: active
name: "{{ pool_name }}"
uri: "qemu:///session"
- name: Autostart session pool
community.libvirt.virt_pool:
autostart: true
name: "{{ pool_name }}"
uri: "qemu:///session"
- name: Start and enable libvirtd service
become: true
ansible.builtin.systemd:
name: libvirtd
enabled: true
state: started