libvirt + restructure

This commit is contained in:
Andrew Wang 2021-09-15 00:46:18 -04:00
parent 3eedd78ed6
commit 06fc399142
10 changed files with 152 additions and 194 deletions

9
group_vars/all.yml Normal file
View File

@ -0,0 +1,9 @@
userdata: "{{playbook_dir}}/userdata"
# ovmf: /usr/share/edk2-ovmf/x64/OVMF_CODE.fd # not required for libvirt
# default value should be nothing to force user to set
ovmf:
vm_ram: 2G
vm_disk_size: 10G
# why is the ssh port on 7777 ?
# we want the user to be able to access this after the install easily
# vm_ssh_port: 7777

1
group_vars/local.yml Normal file
View File

@ -0,0 +1 @@
ansible_connection: local

5
group_vars/vm.yml Normal file
View File

@ -0,0 +1,5 @@
ansible_connection: ssh
# why is the ssh port on 7777 ?
# ansible_port: 7777
ansible_user: ubuntu
ansible_password: ubuntu

6
hosts Normal file
View File

@ -0,0 +1,6 @@
[vm]
mirror ansible_connection=ssh ansible_user=root
# ansible_ssh_private_key_file
[local]
localhost ansible_connection=local

View File

@ -1,26 +1,7 @@
all:
vars:
userdata: "{{playbook_dir}}/userdata"
# ovmf: /usr/share/edk2-ovmf/x64/OVMF_CODE.fd # not required for libvirt
# default value should be nothing to force user to set
ovmf:
vm_ram: 2G
vm_disk_size: 10G
# why is the ssh port on 7777 ?
# we want the user to be able to access this after the install easily
# vm_ssh_port: 7777
children:
local:
hosts:
localhost:
vars:
ansible_connection: local
vm:
hosts:
ubuntu@localhost:
vars:
ansible_connection: ssh
# why is the ssh port on 7777 ?
# ansible_port: 7777
ansible_user: ubuntu
ansible_password: ubuntu
local:
hosts:
localhost:
vm:
hosts:
ubuntu@localhost:

View File

@ -1,2 +0,0 @@
instance-id: mirror-dev
local-hostname: mirror-dev

View File

@ -1,59 +0,0 @@
#cloud-config
autoinstall:
version: 1
identity:
hostname: mirror
username: ubuntu
# 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}

View File

@ -1,110 +1,117 @@
---
- name: Configure all VMs
# Setup mirror VM
- hosts: localhost
# what happened to the host?
tasks:
- name: Check if vm was created already
stat:
path: {{userdata}}/{{vm.name}}
register: vmexists
ignore_errors: true
- name: Check for ubuntu iso
stat:
path: {{role_path}}/files/ubuntu20_04.iso
register: isoexists
ignore_errors: true
- name: Check for ubuntu iso seed
stat:
path: {{userdata}}/{{vm.name}}/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: Check if vm was created already
ansible.buildin.stat:
path: {{ userdata }}/{{ vm.name }}
register: vmexists
- name: Check for ubuntu iso
stat:
path: {{role_path}}/files/ubuntu20_04.iso
register: isoexists
ignore_errors: true
- name: Check for ubuntu iso seed
stat:
path: {{userdata}}/{{vm.name}}/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
# Setting up VM
- name: Create directory for VM
file:
state: directory
path: {{userdata}}/{{vm.name}}
where: vmexists.stat.exists == false
# Setting up VM
- name: Create directory for VM
file:
state: directory
path: {{userdata}}/{{vm.name}}
where: vmexists.stat.exists == false
- name: Fetching ubuntu iso
get_url:
url: https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso
dest: {{role_path}}/files/ubuntu20_04.iso
when: isoexists.stat.exists == false
- name: Fetching ubuntu iso
get_url:
url: https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso
dest: {{role_path}}/files/ubuntu20_04.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
{{userdata}}/{{vm.name}}/seed.qcow2
{{role_path}}/templates/user-data
when: seedexists.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/
# --network-config {{ playbook_dir }}/templates/network
command: >
cloud-localds
{{userdata}}/{{vm.name}}/seed.qcow2
{{role_path}}/templates/user-data
when: seedexists.stat.exists == false
- name: Create storage pool and virtual disks for mirror
command: "virsh {{item}}"
with_items:
- pool-define-as mirror dir --target="{{userdata}}/{{vm.name}}/"
- pool-build mirror
- pool-start mirror
- pool-autostart mirror
command: "virsh vol-create-as mirror {{item}}"
with_items:
- mirror_root1.qcow2 {{vm.disk_size}}
- mirror_root2.qcow2 {{vm.disk_size}}
- mirror_disk1.qcow2 {{vm.disk_size}}
- mirror_disk2.qcow2 {{vm.disk_size}}
- mirror_disk3.qcow2 {{vm.disk_size}}
- mirror_disk4.qcow2 {{vm.disk_size}}
when: not poolexists.rc == 0
- name: Create storage pool and virtual disks for mirror
command: "virsh {{item}}"
with_items:
- pool-define-as mirror dir --target="{{userdata}}/{{vm.name}}/"
- pool-build mirror
- pool-start mirror
- pool-autostart mirror
command: "virsh vol-create-as mirror {{item}}"
with_items:
- mirror_root1.qcow2 {{vm.disk_size}}
- mirror_root2.qcow2 {{vm.disk_size}}
- mirror_disk1.qcow2 {{vm.disk_size}}
- mirror_disk2.qcow2 {{vm.disk_size}}
- mirror_disk3.qcow2 {{vm.disk_size}}
- mirror_disk4.qcow2 {{vm.disk_size}}
when: not poolexists.rc == 0
- name: Create bridge network
# net.ipv4.ip_forward = 1
command: "virsh {{item}}"
with_items:
- net-define {{role_path}}/templates/network.xml
- net-autostart mirbr0
- net-start mirbr0
when: not netexists.rc == 0
- name: Create bridge network
# net.ipv4.ip_forward = 1
command: "virsh {{item}}"
with_items:
- net-define {{role_path}}/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={{userdata}}/{{vm.name}}/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
- name: Create mirror VM
command: >
virt-install
--name=mirror
--memory=2048
--vcpus=1
--boot uefi
--os-type linux --os-variant ubuntu20.04
--disk path={{userdata}}/{{vm.name}}/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
# wait ? seconds (hope that vm is made in forgroud)
# copy over pub key into /root/.ssh/authorized_keys
# add line to ssh config that allows ssh as root
# Configure mirror VM
- hosts: mirror
roles:
- zfs
# - index
# - nginx
- rsync
# - ftp

View File

@ -1,20 +1,23 @@
- name: rsync
apt:
name: rsync
state: latest
update_cache: true
- name: enable and start rsync daemon
systemd:
name: rsync
enabled: true
state: started
- name: add rsync config
- name: copy rsync configs
template:
src: ../templates/rsyncd.conf.j2
dest: /etc/rsyncd.conf
owner: root
group: root
mode: 0644
template:
src: ../templates/rsyncd-filter.conf.j2
dest: /etc/rsyncd-filter.conf
src: templates/{{ item.src }}
dest: /etc/{{ item.dest }}
owner: root
group: root
mode: 0644
with_items:
- { src: "rsyncd.conf.j2", dest: "rsyncd.conf" }
- { src: "rsyncd-filter.conf.j2", dest: "rsyncd-filter.conf" }
notify: restart rsync

View File

@ -1,3 +1,9 @@
- name: install zfs
apt:
name: zfsutils-linux
state: latest
update_cache: true
- name: create zfs mountpoint
file:
path: /mirror/root/.cscmirror
@ -13,3 +19,4 @@
commmand: zpool create -f -m /mirror/root/.cscmirror cscmirror raidz2 /dev/vdc /dev/vdd /dev/vde /dev/vdf
# may need to mount it (also check that it will automount on boot)
# zfs mount -a
# need check for if zpool already exists