|
|
|
@ -1,87 +1,87 @@ |
|
|
|
|
--- |
|
|
|
|
# Setup mirror VM |
|
|
|
|
- hosts: localhost |
|
|
|
|
# what happened to the host? |
|
|
|
|
tasks: |
|
|
|
|
- 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 |
|
|
|
|
- name: gather facts |
|
|
|
|
ignore_errors: true |
|
|
|
|
tasks: |
|
|
|
|
- name: ubuntu iso exists |
|
|
|
|
stat: |
|
|
|
|
path: "{{ playbook_dir }}/vm/ubuntu20_04.iso" |
|
|
|
|
register: iso_exists |
|
|
|
|
|
|
|
|
|
- name: ubuntu iso seed exists |
|
|
|
|
stat: |
|
|
|
|
path: "{{ playbook_dir }}/vm/seed.qcow2" |
|
|
|
|
register: seed_exists |
|
|
|
|
|
|
|
|
|
- name: mirror vm exists |
|
|
|
|
command: "virsh dumpxml mirror > /dev/null 2>&1" |
|
|
|
|
register: vm_exists |
|
|
|
|
|
|
|
|
|
# Setting up VM |
|
|
|
|
- name: Create directory for VM |
|
|
|
|
- name: storage pool exists |
|
|
|
|
command: "virsh pool-dumpxml mirror > /dev/null 2>&1" |
|
|
|
|
register: pool_exists |
|
|
|
|
|
|
|
|
|
- name: mirbr0 network exists |
|
|
|
|
command: "virsh net-dumpxml mirbr0 > /dev/null 2>&1" |
|
|
|
|
register: net_exists |
|
|
|
|
|
|
|
|
|
- name: create directory for vm |
|
|
|
|
file: |
|
|
|
|
path: "{{ playbook_dir }}/vm" |
|
|
|
|
state: directory |
|
|
|
|
path: {{userdata}}/{{vm.name}} |
|
|
|
|
where: vmexists.stat.exists == false |
|
|
|
|
|
|
|
|
|
- name: Fetching ubuntu iso |
|
|
|
|
|
|
|
|
|
- name: fetch 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 |
|
|
|
|
dest: "{{ playbook_dir }}/vm/ubuntu20_04.iso" |
|
|
|
|
when: iso_exists.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 |
|
|
|
|
# requires: cloud-localds (cloud-image-utils) |
|
|
|
|
|
|
|
|
|
# Installing VMs from Ready Images |
|
|
|
|
# https://www.x386.xyz/index.php/2021/01/06/kvm-on-ubuntu-server-1/ |
|
|
|
|
|
|
|
|
|
# apply network config |
|
|
|
|
# --network-config {{ playbook_dir }}/templates/network |
|
|
|
|
- name: create ubuntu iso seed |
|
|
|
|
command: > |
|
|
|
|
cloud-localds |
|
|
|
|
{{userdata}}/{{vm.name}}/seed.qcow2 |
|
|
|
|
{{role_path}}/templates/user-data |
|
|
|
|
when: seedexists.stat.exists == false |
|
|
|
|
{{ playbook_dir }}/vm/seed.qcow2 |
|
|
|
|
{{ playbook_dir }}/templates/user-data |
|
|
|
|
when: seed_exists.stat.exists == false |
|
|
|
|
|
|
|
|
|
# get user to set net.ipv4.ip_forward = 1 ? |
|
|
|
|
- name: create mirbr0 bridge network |
|
|
|
|
command: "virsh {{ item }}" |
|
|
|
|
with_items: |
|
|
|
|
- net-define {{ playbook_dir }}/templates/network.xml |
|
|
|
|
- net-autostart mirbr0 |
|
|
|
|
- net-start mirbr0 |
|
|
|
|
when: not net_exists.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 storage pool |
|
|
|
|
command: "virsh {{ item }}" |
|
|
|
|
with_items: |
|
|
|
|
- pool-define-as mirror dir --target="{{ playbook_dir }}/vm/" |
|
|
|
|
- pool-build mirror |
|
|
|
|
- pool-start mirror |
|
|
|
|
- pool-autostart mirror |
|
|
|
|
when: not pool_exists.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 |
|
|
|
|
# any way to check skip virtual disks that are already created? |
|
|
|
|
# for now just hardcoding size as 10G since will need to mod user-data to use different values |
|
|
|
|
- name: create virtual disks |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
- name: Create mirror VM |
|
|
|
|
- name: create vm |
|
|
|
|
command: > |
|
|
|
|
virt-install |
|
|
|
|
--name=mirror |
|
|
|
@ -89,7 +89,7 @@ |
|
|
|
|
--vcpus=1 |
|
|
|
|
--boot uefi |
|
|
|
|
--os-type linux --os-variant ubuntu20.04 |
|
|
|
|
--disk path={{userdata}}/{{vm.name}}/seed.qcow2,device=cdrom |
|
|
|
|
--disk path={{ playbook_dir }}/vm/seed.qcow2,device=cdrom |
|
|
|
|
--disk vol=mirror/mirror_root1.qcow2 |
|
|
|
|
--disk vol=mirror/mirror_root2.qcow2 |
|
|
|
|
--disk vol=mirror/mirror_disk1.qcow2 |
|
|
|
@ -99,19 +99,18 @@ |
|
|
|
|
--network bridge=mirbr0 |
|
|
|
|
--graphics vnc,port=5911,listen=127.0.0.1 |
|
|
|
|
--noautoconsole |
|
|
|
|
when: not vmexists.rc == 0 |
|
|
|
|
when: not vm_exists.rc == 0 |
|
|
|
|
# in the vm to disable cloud-init run |
|
|
|
|
# sudo touch /etc/cloud/cloud-init.disabled |
|
|
|
|
|
|
|
|
|
# wait ? seconds (hope that vm is made in forgroud) |
|
|
|
|
# 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 |
|
|
|
|
|
|
|
|
|
# Configure mirror VM |
|
|
|
|
- hosts: mirror |
|
|
|
|
- hosts: 192.168.123.2 |
|
|
|
|
roles: |
|
|
|
|
- zfs |
|
|
|
|
# - index |
|
|
|
|
# - nginx |
|
|
|
|
- rsync |
|
|
|
|
# - rsync |
|
|
|
|
# - ftp |
|
|
|
|