add libvirt playbook
This commit is contained in:
parent
45742ccac7
commit
1f16debf42
|
@ -0,0 +1,3 @@
|
|||
*.iso
|
||||
disks/
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
```
|
||||
- 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
|
|
@ -10,43 +10,8 @@ $ apt install qemu-kvm libvirt virt-install virt-viewer
|
|||
install (arch)
|
||||
$ pacman -S qemu libvirt virt-install virt-viewer
|
||||
|
||||
start and set autostart libvirtd
|
||||
$ systemctl enable --now libvirtd
|
||||
$ virsh
|
||||
troubleshooting: try to load the kvm module with `modprobe kvm_intel`
|
||||
|
||||
create storage pool for mirror
|
||||
> pool-define-as mirror dir --target="~/.local/mirror/images"
|
||||
> pool-build mirror
|
||||
> pool-start mirror
|
||||
> pool-autostart mirror
|
||||
|
||||
create virtual disks
|
||||
> vol-create-as mirror mirror_root1.qcow2 10G
|
||||
> vol-create-as mirror mirror_root2.qcow2 10G
|
||||
> vol-create-as mirror mirror_disk1.qcow2 5G
|
||||
> vol-create-as mirror mirror_disk2.qcow2 5G
|
||||
> vol-create-as mirror mirror_disk3.qcow2 5G
|
||||
> vol-create-as mirror mirror_disk4.qcow2 5G
|
||||
(exit virsh shell)
|
||||
|
||||
get ubuntu iso
|
||||
$ curl -O https://releases.ubuntu.com/20.04/ubuntu-20.04.2-live-server-amd64.iso
|
||||
|
||||
create the vm
|
||||
$ virt-install \
|
||||
--name=mirror \
|
||||
--memory=2048 \
|
||||
--vcpus=1 \
|
||||
--boot uefi \
|
||||
--location="./ubuntu-20.04.2-live-server-amd64.iso" \
|
||||
--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 \
|
||||
|
||||
interface should automatically come up but can also use
|
||||
$ virt-viewer --domain-name mirror
|
||||
if vm is on a remote machine
|
|
@ -0,0 +1,12 @@
|
|||
# set up static ip
|
||||
# https://askubuntu.com/questions/1029531/how-to-setup-a-static-ip-on-ubuntu-server-18-04
|
||||
|
||||
#cloud-config
|
||||
version: 2
|
||||
ethernets:
|
||||
enp1s0:
|
||||
dhcp4: false
|
||||
addresses: [ 192.168.0.221/24 ]
|
||||
gateway4: 192.168.0.1
|
||||
nameservers:
|
||||
addresses: [ 192.168.0.1,8.8.8.8 ]
|
|
@ -0,0 +1,60 @@
|
|||
#cloud-config
|
||||
autoinstall:
|
||||
version: 1
|
||||
identity:
|
||||
hostname: mirror
|
||||
username: ubuntu
|
||||
# mkpasswd --method=SHA-512 --rounds=4096
|
||||
# password is just ubuntu
|
||||
password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
|
||||
locale: en_US
|
||||
ssh:
|
||||
allow-pw: true
|
||||
authorized-keys: []
|
||||
install-server: true
|
||||
storage:
|
||||
config:
|
||||
# disks =-=-=-=-=-=-=
|
||||
- {id: vda, name: '', path: /dev/vda, type: disk, ptable: gpt,
|
||||
preserve: false, grub_device: false}
|
||||
- {id: vdb, name: '', path: /dev/vdb, type: disk, ptable: gpt,
|
||||
preserve: false, grub_device: false}
|
||||
# partitions =-=-=-=-=-=
|
||||
# vda1
|
||||
- {id: vda1, type: partition, size: 500M, device: vda, number: 1,
|
||||
preserve: false, wipe: superblock, flag: boot, grub_device: true}
|
||||
- {id: vda1-format, type: format, volume: vda1,
|
||||
fstype: fat32, preserve: false}
|
||||
# vda2
|
||||
- {id: vda2, type: partition, size: 9G, device: vda, number: 2,
|
||||
preserve: false, wipe: superblock, flag: '', grub_device: false}
|
||||
# vdb1
|
||||
- {id: vdb1, type: partition, size: 500M, device: vdb, number: 1,
|
||||
preserve: false, wipe: superblock, flag: boot, grub_device: true}
|
||||
- {id: vdb1-format, type: format, volume: vdb1,
|
||||
fstype: fat32, preserve: false}
|
||||
# vdb2
|
||||
- {id: vdb2, type: partition, size: 9G, device: vdb, number: 2,
|
||||
preserve: false, wipe: superblock, flag: '', grub_device: false}
|
||||
# raid =-=-=-=-=-=
|
||||
- id: md0
|
||||
name: md0
|
||||
type: raid
|
||||
raidlevel: raid1
|
||||
devices: [vda2, vdb2]
|
||||
spare_devices: []
|
||||
preserve: false
|
||||
# lvm =-=-=-=-=-=
|
||||
- id: vg0
|
||||
name: vg0
|
||||
type: lvm_volgroup
|
||||
devices: [md0]
|
||||
preserve: false
|
||||
# partition
|
||||
- {id: vg0-root, name: root, type: lvm_partition, size: 8G,
|
||||
preserve: false, volgroup: vg0}
|
||||
- {id: vg0-root-format, type: format, volume: vg0-root,
|
||||
fstype: ext4, preserve: false}
|
||||
# mount points =-=-=-=-=-=
|
||||
- {id: boot-mount, type: mount, path: /boot/efi, device: vda1-format}
|
||||
- {id: root-mount, type: mount, path: /, device: vg0-root-format}
|
|
@ -28,3 +28,28 @@ create network and storage interface?
|
|||
<listen type='address' address='127.0.0.1'/>
|
||||
</graphics>
|
||||
|
||||
interface should automatically come up but can also use
|
||||
$ virt-viewer --domain-name mirror
|
||||
if vm is on a remote machine
|
||||
$ virt-viewer --connect qemu+ssh://user@host.example.com/system vmnamehere
|
||||
|
||||
for now just have a folder of screenshots
|
||||
- change name of lvm volume from "lv0-root" to just "root"
|
||||
troubleshooting: ignore "failed to unmount /cdrom" and just ctrl+c in viewer
|
||||
|
||||
login into your created user (from install), change to root, and create password for root
|
||||
$ sudo su
|
||||
type in your password
|
||||
$ passwd
|
||||
create root password
|
||||
|
||||
create zpool (use /dev/disk/by-id/.. instead)
|
||||
$ apt update
|
||||
$ apt install zfsutils-linux nginx rsync
|
||||
$ mkdir -p /mirror/root/.cscmirror
|
||||
$ zpool create -f -m /mirror/root/.cscmirror cscmirror raidz2 /dev/vdc /dev/vdd /dev/vde /dev/vdf
|
||||
|
||||
may already be mounted but just to be sure
|
||||
$ zfs mount -a
|
||||
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
## TODO
|
||||
modify configs when appropriate
|
||||
- modify configs when appropriate
|
||||
- net.ipv4.ip_forward=1 for both host and vm
|
||||
|
||||
### Storage
|
||||
symlink projects from `/mirror/root/.cscmirror` to `/mirror/root`
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
---
|
||||
- name: create mirror vm
|
||||
hosts: localhost
|
||||
connection: local
|
||||
|
||||
|
||||
start and set autostart libvirtd
|
||||
$ systemctl enable --now libvirtd
|
||||
$ virsh
|
||||
troubleshooting: try to load the kvm module with `modprobe kvm_intel`
|
||||
|
||||
create storage pool for mirror
|
||||
> pool-define-as mirror dir --target="~/.local/mirror/images"
|
||||
> pool-build mirror
|
||||
> pool-start mirror
|
||||
> pool-autostart mirror
|
||||
|
||||
create virtual disks
|
||||
> vol-create-as mirror mirror_root1.qcow2 10G
|
||||
> vol-create-as mirror mirror_root2.qcow2 10G
|
||||
> vol-create-as mirror mirror_disk1.qcow2 5G
|
||||
> vol-create-as mirror mirror_disk2.qcow2 5G
|
||||
> vol-create-as mirror mirror_disk3.qcow2 5G
|
||||
> vol-create-as mirror mirror_disk4.qcow2 5G
|
||||
(exit virsh shell)
|
||||
|
||||
get ubuntu iso
|
||||
$ curl -O https://releases.ubuntu.com/20.04/ubuntu-20.04.2-live-server-amd64.iso
|
||||
|
||||
create the vm
|
||||
$ virt-install \
|
||||
--name=mirror \
|
||||
--memory=2048 \
|
||||
--vcpus=1 \
|
||||
--boot uefi \
|
||||
--location="./ubuntu-20.04.2-live-server-amd64.iso" \
|
||||
--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 \
|
||||
|
||||
interface should automatically come up but can also use
|
||||
$ virt-viewer --domain-name mirror
|
||||
if vm is on a remote machine
|
||||
$ virt-viewer --connect qemu+ssh://user@host.example.com/system vmnamehere
|
||||
|
||||
for now just have a folder of screenshots
|
||||
- change name of lvm volume from "lv0-root" to just "root"
|
||||
troubleshooting: ignore "failed to unmount /cdrom" and just ctrl+c in viewer
|
||||
|
||||
login into your created user (from install), change to root, and create password for root
|
||||
$ sudo su
|
||||
type in your password
|
||||
$ passwd
|
||||
create root password
|
||||
|
||||
create zpool (use /dev/disk/by-id/.. instead)
|
||||
$ apt update
|
||||
$ apt install zfsutils-linux nginx rsync
|
||||
$ mkdir -p /mirror/root/.cscmirror
|
||||
$ zpool create -f -m /mirror/root/.cscmirror cscmirror raidz2 /dev/vdc /dev/vdd /dev/vde /dev/vdf
|
||||
|
||||
may already be mounted but just to be sure
|
||||
$ zfs mount -a
|
||||
|
Loading…
Reference in New Issue