diff --git a/libvirt/README.md b/libvirt/README.md new file mode 100644 index 0000000..a7aecd6 --- /dev/null +++ b/libvirt/README.md @@ -0,0 +1,24 @@ +then service libvirtd restart + +adduser libvirt +adduser -aG libvirt + +To create the vm run the command +``` +ansible-playbook main.yml +``` + +## Troubleshooting +``` +net.ipv4.ip_forward = 1 ? +``` +``` +modprobe kvm_intel +``` +If running in `/root` may need to edit config +``` +# edit /etc/libvirt/qemu.conf +user = "root" +group = "root" +$ service restart libvirtd +``` diff --git a/libvirt/main.yml b/libvirt/main.yml index f37226f..d88c9d2 100644 --- a/libvirt/main.yml +++ b/libvirt/main.yml @@ -29,13 +29,13 @@ - 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" - url: "http://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img" - dest: "{{ playbook_dir }}/vm/focal-server-cloudimg-amd64.img" + url: "https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso" + dest: "{{ playbook_dir }}/vm/ubuntu20_04.iso" - # Installing VMs from Ready Images - # https://www.x386.xyz/index.php/2021/01/06/kvm-on-ubuntu-server-1/ + # autoinstall not working for libvirt + # https://manintheit.org/en/posts/automation/ubuntu-autoinstall/ + # https://ubuntu.com/server/docs/install/autoinstall-quickstart + # # --network-config {{ playbook_dir }}/templates/network # - name: create ubuntu iso seed # command: @@ -55,19 +55,6 @@ # {{ playbook_dir }}/templates/meta-data # creates: "{{ playbook_dir }}/vm/seed.iso" -# # ??? -# - name: create new image -# command: -# cmd: > -# qemu-img create -# -b {{ playbook_dir }}/focal-server-cloudimg-amd64.img -# -f qcow2 -# -F qcow2 -# {{ playbook_dir }}/vm/mirror.img -# creates: "{{ playbook_dir }}/vm/mirror.img" - - - - name: create mirbr0 bridge network command: "virsh {{ item }}" loop: @@ -85,7 +72,7 @@ - pool-start mirror when: pool_exists.rc != 0 - # hardcoded to 10G since modification would require change to user-data + # TODO: allow user to create any number of disks with any size - name: create virtual disks command: cmd: "virsh vol-create-as mirror {{ item.name }} {{ item.size }}" @@ -103,6 +90,8 @@ # --cdrom path={{ playbook_dir }}/vm/ubuntu20_04.iso # --disk path={{ playbook_dir }}/vm/seed.iso,format=raw,bus=virtio + # --cloud-init user-data={{ playbook_dir }}/templates/user-data,meta-data={{ playbook_dir }}/templates/meta-data + # --disk path={{ playbook_dir }}/vm/focal-server-cloudimg-amd64.img - name: create vm command: > virt-install @@ -111,8 +100,7 @@ --vcpus=1 --boot uefi --os-type linux - --cloud-init user-data={{ playbook_dir }}/templates/user-data, meta-data={{ playbook_dir }}/templates/meta-data - --disk path={{ playbook_dir }}/vm/focal-server-cloudimg-amd64.img + --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 @@ -122,58 +110,4 @@ --network bridge=mirbr0,model=virtio --graphics vnc,port=5911,listen=127.0.0.1 --noautoconsole - when: vm_exists.rc != 0 - # get user to set net.ipv4.ip_forward = 1 ? - - # in the vm to disable cloud-init run - # sudo touch /etc/cloud/cloud-init.disabled - - # wait ? seconds (hope that vm is made in foreground) - # copy over pub key into /root/.ssh/authorized_keys - # add line to ssh config that allows ssh as root - - # modprobe kvm_intel - - # depending on where you are installing may need to edit - # /etc/libvirt/qemu.conf - # user = "root" - # group = "root" - - # then service libvirtd restart - - # adduser libvirt - # adduser -aG libvirt - -# this should execute in order right? -- name: setup mirror vm - hosts: 192.168.123.2 -# - modify ssh config to allow root login -# - copy over ssh public keys (if provided) - roles: - - "../roles/system" - - "../roles/mirror" - # - "../roles/ftp" - # - "../roles/nginx" - # - "../roles/rsync" - # tasks: - # allow root login from here - # become: root - - # loop does not work... - # - name: setup system - # import_role: - # name: "../roles/system" - # - name: setup mirror - # import_role: - # name: "../roles/mirror" - # - name: setup ftp - # import_role: - # name: "../roles/ftp" - # - name: setup nginx - # import_role: - # name: "../roles/nginx" - # - name: setup rsync - # import_role: - # name: "../roles/rsync" - # - name: setup rsync - # import_role: "../roles/mirrormanager" \ No newline at end of file + when: vm_exists.rc != 0 \ No newline at end of file diff --git a/libvirt/templates/meta-data b/libvirt/templates/meta-data deleted file mode 100644 index e69de29..0000000 diff --git a/libvirt/templates/network b/libvirt/templates/network deleted file mode 100644 index 452f085..0000000 --- a/libvirt/templates/network +++ /dev/null @@ -1,12 +0,0 @@ -#cloud-config -version: 2 -ethernets: - enp1s0: - dhcp4: false - addresses: [ 192.168.123.2/24 ] - gateway4: 192.168.123.1 - nameservers: - addresses: [ 1.1.1.1 ] - -# set up static ip -# https://askubuntu.com/questions/1029531/how-to-setup-a-static-ip-on-ubuntu-server-18-04 diff --git a/libvirt/templates/user-data b/libvirt/templates/user-data deleted file mode 100644 index b288fdf..0000000 --- a/libvirt/templates/user-data +++ /dev/null @@ -1,62 +0,0 @@ -#cloud-config -autoinstall: - version: 1 - identity: - hostname: mirror - username: local - # mkpasswd --method=SHA-512 --rounds=4096 - # password is krb5 - password: "$6$rounds=4096$FfXwns8mexFJUAjS$z/ERS/5gitnl8f3AZnnztS8iFpmS/AtzUfEVM2.tfRpWnl/y7PwhDZTeT68WxoogmSTgaZyVL6..jP4aiB1LD0" - # this password is ubuntu - # $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} \ No newline at end of file diff --git a/local/README.md b/local/README.md deleted file mode 100644 index e14b6a7..0000000 --- a/local/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# local playbook -this playbook will be run inside a already set up vm to set up the services - -used if someone wants to set up vm themselves + wants more disks in the pool - -includes varable for which disks to turn into a zfs pool - diff --git a/mirror/README.md b/mirror/README.md new file mode 100644 index 0000000..25f69bb --- /dev/null +++ b/mirror/README.md @@ -0,0 +1,4 @@ +# mirror playbook +this playbook will be run inside a already set up vm to set up the services + +TODO: varable for which disks to turn into a zfs pool \ No newline at end of file diff --git a/mirror/main.yml b/mirror/main.yml new file mode 100644 index 0000000..a75d42f --- /dev/null +++ b/mirror/main.yml @@ -0,0 +1,11 @@ +- name: setup mirror vm + hosts: 127.0.0.1 +# - modify ssh config to allow root login +# - copy over ssh public keys (if provided) + roles: + - "../roles/system" + - "../roles/mirror" + # - "../roles/ftp" + # - "../roles/nginx" + # - "../roles/rsync" + # TODO: - "../roles/mirrormanager" \ No newline at end of file