restructure

autoautoinstall
Andrew Wang 1 year ago
parent 207aa9fd5f
commit 3eedd78ed6
  1. 13
      hosts.yml
  2. 0
      libvirt/files/meta-data
  3. 0
      libvirt/files/user-data
  4. 122
      libvirt/main.yml
  5. 2
      libvirt/main.yml.orig
  6. 55
      libvirt/thing
  7. 10
      mirror-vm.yml
  8. 0
      qemu/files/meta-data
  9. 0
      qemu/files/user-data
  10. 0
      qemu/main.yml
  11. 0
      qemu/run-vm.yml
  12. 6
      roles/vm-libvirt/tasks/main.yml
  13. 108
      roles/vm-libvirt/tasks/vm.yml
  14. 12
      roles/vm-libvirt/templates/network
  15. 14
      roles/vm-libvirt/templates/network.xml
  16. 60
      roles/vm-libvirt/templates/user-data
  17. 0
      tasks/a
  18. 15
      todo/mirror-vm.yml
  19. 0
      todo/mirror.txt
  20. 2
      todo/post-install.yml

@ -1,10 +1,14 @@
all:
vars:
userdata: "{{playbook_dir}}/userdata"
ovmf: /usr/share/edk2-ovmf/x64/OVMF_CODE.fd # not required for libvirt
vm_ram: 3G
# 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
vm_ssh_port: 7777
# 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:
@ -16,6 +20,7 @@ all:
ubuntu@localhost:
vars:
ansible_connection: ssh
ansible_port: 7777
# why is the ssh port on 7777 ?
# ansible_port: 7777
ansible_user: ubuntu
ansible_password: ubuntu

@ -1,42 +1,48 @@
```
- name: Create mirror VM
hosts: localhost
connection: local
---
- name: Configure all VMs
# what happened to the host?
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: 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
# 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: Create ubuntu iso
# install cloud-localds (cloud-image-utils)
#
@ -45,39 +51,36 @@
command: >
cloud-localds
# --network-config {{ playbook_dir }}/templates/network
{{ playbook_dir }}/ubuntu-seed.qcow2
{{ playbook_dir }}/templates/user-data
when: seedexists.stat.exists == False
{{userdata}}/{{vm.name}}/seed.qcow2
{{role_path}}/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 }}"
command: "virsh {{item}}"
with_items:
- pool-define-as mirror dir --target="{{ playbook_dir }}/disks"
- 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 }}"
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
- 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 }}"
command: "virsh {{item}}"
with_items:
- net-define {{ playbook_dir }}/templates/network.xml
- 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
@ -86,7 +89,7 @@
--vcpus=1
--boot uefi
--os-type linux --os-variant ubuntu20.04
--disk path={{ playbook_dir }}/ubuntu-seed.qcow2,device=cdrom
--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
@ -104,3 +107,4 @@
# 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

@ -1,5 +1,5 @@
```
- name: Create mirror Vm
- name: Create mirror VM
hosts: localhost
connection: local
tasks:

@ -1,55 +0,0 @@
create network and storage interface?
<interface type='network'>
<mac address='52:54:00:64:dd:f2'/>
<source network='default' bridge='virbr0'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
<graphics type='spice' port='5900' autoport='yes' listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'/>
<image compression='off'/>
</graphics>
<graphics type='vnc' port='5901' autoport='yes' listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<graphics type='spice' port='5902' autoport='yes' listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'/>
<image compression='off'/>
</graphics>
<graphics type='vnc' port='5903' autoport='yes' listen='127.0.0.1'>
<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,10 +0,0 @@
---
# - hosts: local
# roles:
# - vm-qemu
# - run-vm
- hosts: vm
become: yes
roles:
- nginx

@ -1,6 +0,0 @@
---
- name: Configure all VMs
include_tasks: vm.yml
loop: {{ virtual_machines }}
loop_control:
loop_var: vm

@ -1,108 +0,0 @@
---
# Gather info
- 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
# 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: 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 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 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

@ -1,12 +0,0 @@
# 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 ]

@ -1,14 +0,0 @@
<network>
<name>mirbr0</name>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='mirbr0' stp='on' delay='0'/>
<ip address='192.168.123.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.123.2' end='192.168.123.254'/>
</dhcp>
</ip>
</network>

@ -1,60 +0,0 @@
#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}

@ -0,0 +1,15 @@
# instead of this we can just get the user to run
# ansible-playbook qemu/main.yml
# or
# ansible-playbook libvirt/main.yml
---
# - hosts: local
# roles:
# - vm-qemu
# - run-vm
- hosts: vm
become: yes
roles:
- nginx

@ -1,3 +1,5 @@
# don't really need anymore
# just keeping here for reference
---
- name: install dependencies
apt:
Loading…
Cancel
Save