A dev environment for the mirror.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
mirror-env/libvirt/main.yml

86 lines
2.9 KiB

---
- name: setup mirror vm
hosts: 127.0.0.1
gather_facts: no
become: yes
tasks:
- name: mirbr0 network exists
command: "virsh -c qemu:///system net-dumpxml mirbr0"
changed_when: false
ignore_errors: true
register: net_exists
- name: storage pool exists
command: "virsh -c qemu:///system pool-dumpxml mirror"
changed_when: false
ignore_errors: true
register: pool_exists
- name: mirror vm exists
command: "virsh -c qemu:///system dumpxml mirror"
changed_when: false
ignore_errors: true
register: vm_exists
- name: create directory for vm
file:
path: "{{ playbook_dir }}/vm"
state: directory
recurse: yes
- name: fetch ubuntu iso
get_url:
url: "https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso"
dest: "{{ playbook_dir }}/vm/ubuntu20_04.iso"
- name: create mirbr0 bridge network
command: "virsh -c qemu:///system {{ item }}"
loop:
- net-define {{ playbook_dir }}/templates/network.xml
- net-autostart mirbr0
- net-start mirbr0
when: net_exists.rc != 0
- name: create storage pool
command: "virsh -c qemu:///system {{ item }}"
loop:
- pool-define-as mirror dir --target="{{ playbook_dir }}/vm"
- pool-build mirror
- pool-autostart mirror
- pool-start mirror
when: pool_exists.rc != 0
- name: create virtual disks
command:
cmd: "virsh -c qemu:///system vol-create-as mirror {{ item.name }} {{ item.size }}"
creates: "{{ playbook_dir }}/vm/{{ item.name }}"
loop:
- { name: mirror_root1.qcow2, size: "{{ root_disks_size }}" }
- { name: mirror_root2.qcow2, size: "{{ root_disks_size }}" }
- { name: mirror_disk1.qcow2, size: "{{ zfs_disks_size }}" }
- { name: mirror_disk2.qcow2, size: "{{ zfs_disks_size }}" }
- { name: mirror_disk3.qcow2, size: "{{ zfs_disks_size }}" }
- { name: mirror_disk4.qcow2, size: "{{ zfs_disks_size }}" }
- name: create vm
# flag does not work:
# --os-variant ubuntu20.04
command: >
virt-install
--connect=qemu:///system
--name=mirror
--memory={{ vm_ram }}
--vcpus={{ vm_vcpus }}
--boot uefi
--os-type linux
--cdrom {{ playbook_dir }}/vm/ubuntu20_04.iso
--disk vol=mirror/mirror_root1.qcow2,bus=virtio
--disk vol=mirror/mirror_root2.qcow2,bus=virtio
--disk vol=mirror/mirror_disk1.qcow2,bus=virtio
--disk vol=mirror/mirror_disk2.qcow2,bus=virtio
--disk vol=mirror/mirror_disk3.qcow2,bus=virtio
--disk vol=mirror/mirror_disk4.qcow2,bus=virtio
--network bridge=mirbr0,model=virtio
--graphics vnc,port={{ vnc_port }},listen=127.0.0.1
--noautoconsole
when: vm_exists.rc != 0