added back qemu vm

autoautoinstall
Daniel Liu 1 year ago
parent 076dc6f191
commit d5b90baecf
  1. 13
      hosts.yml
  2. 2
      mirror-vm.yml
  3. 0
      roles/vm-libvirt/files/meta-data
  4. 0
      roles/vm-libvirt/files/user-data
  5. 0
      roles/vm-libvirt/tasks/main-libvirt.yml
  6. 0
      roles/vm-libvirt/tasks/main.yml
  7. 0
      roles/vm-libvirt/tasks/vm.yml
  8. 0
      roles/vm-libvirt/templates/network
  9. 0
      roles/vm-libvirt/templates/network.xml
  10. 0
      roles/vm-libvirt/templates/user-data
  11. 2
      roles/vm-qemu/files/meta-data
  12. 59
      roles/vm-qemu/files/user-data
  13. 6
      roles/vm-qemu/tasks/main.yml
  14. 40
      roles/vm-qemu/tasks/vm.yml

@ -1,17 +1,16 @@
local:
hosts:
localhost
localhost:
vars:
ansible_connection: local
userdata: {{playbook_dir}}/userdata
userdata: "{{playbook_dir}}/userdata"
virtual_machines:
- name: mirror-env
ram: 2G
disk_size: 10G
- name: mirror-env
ram: 2G
disk_size: 10G
vm:
hosts:
ubuntu@localhost
ubuntu@localhost:
vars:
ansible_connection: ssh
ansible_port: 7777

@ -2,4 +2,4 @@
- hosts: local
become: true
roles:
- vm
- vm-qemu

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

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

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

@ -0,0 +1,40 @@
---
# quite a lot of duplication, probably fix later
# 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.iso"
register: seedexists
ignore_errors: true
# Setting up VM
- name: Create directory for VM
file:
state: directory
path: "{{userdata}}/{{vm.name}}"
when: vmexists.stat.exists == false
# didn't use get_url module since it broke with symlinks
- name: Fetching ubuntu iso
command: curl -o "{{role_path}}/files/ubuntu20_04.iso" https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso
when: isoexists.stat.exists == false
- name: Create disk images
shell:
cmd: "for i in {1..6}; do qemu-img create -f qcow2 {{userdata}}/{{vm.name}}/drive${i} {{vm.disk_size}}; done"
when: vmexists.stat.exists == false
- name: Creating cloud-init iso
command: "genisoimage -output {{userdata}}/{{vm.name}}/seed.iso -volid cidata -joliet -rock {{role_path}}/files/user-data {{role_path}}/files/meta-data"
when: seedexists.stat.exists == false
Loading…
Cancel
Save