107 lines
3.2 KiB
YAML
107 lines
3.2 KiB
YAML
```
|
|
- name: Create mirror Vm
|
|
hosts: localhost
|
|
connection: local
|
|
tasks:
|
|
- name: Check for ubuntu iso
|
|
stat:
|
|
path: {{ playbook_dir }}/ubuntu.iso
|
|
register: isoexists
|
|
ignore_errors: true
|
|
- name: Check for ubuntu iso seed
|
|
stat:
|
|
path: {{ playbook_dir }}/ubuntu-seed.qcow2
|
|
register: seedexists
|
|
ignore_errors: true
|
|
- name: Check if storage pool exists
|
|
command: virsh pool-info mirror
|
|
register: poolexists
|
|
ignore_errors: true
|
|
- name: Check if mirbr0 network exists
|
|
command: virsh net-info mirbr0
|
|
register: netexists
|
|
ignore_errors: true
|
|
- name: Check if mirror VM exists
|
|
command: virsh dumpxml mirror
|
|
register: vmexists
|
|
ignore_errors: true
|
|
- name: enable and start libvirt daemon
|
|
systemd:
|
|
name: libvirtd
|
|
enabled: true
|
|
state: started
|
|
- name: Download ubuntu iso
|
|
# make sure curl is installed ?
|
|
command: >
|
|
curl
|
|
-o {{ playbook_dir }}/ubuntu.iso
|
|
https://releases.ubuntu.com/20.04/ubuntu-20.04.2-live-server-amd64.iso
|
|
when: isoexists.stat.exists == False
|
|
- name: Create ubuntu iso
|
|
# install cloud-localds (cloud-image-utils)
|
|
#
|
|
# Installing VMs from Ready Images
|
|
# https://www.x386.xyz/index.php/2021/01/06/kvm-on-ubuntu-server-1/
|
|
command: >
|
|
cloud-localds
|
|
# --network-config {{ playbook_dir }}/templates/network
|
|
{{ playbook_dir }}/ubuntu-seed.qcow2
|
|
{{ playbook_dir }}/templates/user-data
|
|
when: seedexists.stat.exists == False
|
|
- name: Create storage pool and virtual disks for mirror
|
|
file:
|
|
path: {{ playbook_dir }}/disks
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: 0711
|
|
command: "virsh {{ item }}"
|
|
with_items:
|
|
- pool-define-as mirror dir --target="{{ playbook_dir }}/disks"
|
|
- pool-build mirror
|
|
- pool-start mirror
|
|
- pool-autostart mirror
|
|
command: "virsh vol-create-as mirror {{ item }}"
|
|
with_items:
|
|
- mirror_root1.qcow2 10G
|
|
- mirror_root2.qcow2 10G
|
|
- mirror_disk1.qcow2 10G
|
|
- mirror_disk2.qcow2 10G
|
|
- mirror_disk3.qcow2 10G
|
|
- mirror_disk4.qcow2 10G
|
|
when: not poolexists.rc == 0
|
|
- name: Create bridge network
|
|
# net.ipv4.ip_forward = 1
|
|
command: "virsh {{ item }}"
|
|
with_items:
|
|
- net-define {{ playbook_dir }}/templates/network.xml
|
|
- net-autostart mirbr0
|
|
- net-start mirbr0
|
|
when: not netexists.rc == 0
|
|
- name: Create mirror VM
|
|
command: >
|
|
virt-install
|
|
--name=mirror
|
|
--memory=2048
|
|
--vcpus=1
|
|
--boot uefi
|
|
--os-type linux --os-variant ubuntu20.04
|
|
--disk path={{ playbook_dir }}/ubuntu-seed.qcow2,device=cdrom
|
|
--disk vol=mirror/mirror_root1.qcow2
|
|
--disk vol=mirror/mirror_root2.qcow2
|
|
--disk vol=mirror/mirror_disk1.qcow2
|
|
--disk vol=mirror/mirror_disk2.qcow2
|
|
--disk vol=mirror/mirror_disk3.qcow2
|
|
--disk vol=mirror/mirror_disk4.qcow2
|
|
--network bridge=mirbr0
|
|
--graphics vnc,port=5911,listen=127.0.0.1
|
|
--noautoconsole
|
|
when: not vmexists.rc == 0
|
|
# in the vm to disable cloud-init run
|
|
# sudo touch /etc/cloud/cloud-init.disabled
|
|
|
|
# next
|
|
# wait ? seconds (hope that vm is made in forgroud)
|
|
# update ssh config to allow root login (and add passwd to root)
|
|
# copy pub key and relogin as root
|