add cleanup playbook for libvirt

master
Andrew Wang 1 year ago
parent 0204237618
commit 2834d86e92
  1. 1
      README.md
  2. 13
      libvirt/README.md
  3. 49
      libvirt/cleanup.yml
  4. 1
      libvirt/main.yml

@ -16,6 +16,7 @@ Follow instructions in the [readme](qemu/README.md) of the qemu directory.
Follow the instructions in [readme](libvirt/README.md) of the libirt directory.
## Issues/Remarks
- vm is set to autostart when installing using libvirt playbook
- cron config `/etc/cron.d/csc-mirror` is commented out for now
- merlin.service is NOT started
- outsider/insider

@ -26,9 +26,8 @@ $ pacman -S qemu libvirt virt-install virt-viewer ansible
```
## Running the Playbook
Run the playbook from one directory down
```
ansible-playbook -K libvirt/main.yml
ansible-playbook -K main.yml
```
Then connect to the created vm using virt-viewer
```
@ -67,6 +66,14 @@ $ apt install git ansible
$ git clone https://git.csclub.uwaterloo.ca/public/mirror-env.git
```
Then enter `mirror-env/mirror` and follow the instructions there.
## Deleting the VM
The VM and everything related can be removed by running the `cleanup.yml` playbook
```
ansible-playbook -K cleanup.yml
```
## Troubleshooting
```
@ -75,7 +82,7 @@ net.ipv4.ip_forward = 1
```
modprobe kvm_intel
```
If running in `/root` may need to edit config
If running as `root` may need to edit config
```
# edit /etc/libvirt/qemu.conf
user = "root"

@ -0,0 +1,49 @@
---
- name: delete the mirror vm
hosts: 127.0.0.1
gather_facts: no
become: yes
tasks:
- name: mirbr0 network exists
command: "virsh net-dumpxml mirbr0"
changed_when: false
ignore_errors: true
register: net_exists
- name: storage pool exists
command: "virsh pool-dumpxml mirror"
changed_when: false
ignore_errors: true
register: pool_exists
- name: mirror vm exists
command: "virsh dumpxml mirror"
changed_when: false
ignore_errors: true
register: vm_exists
- name: delete vm
command: "virsh {{ item }}"
loop:
- destroy mirror
- undefine mirror
when: vm_exists.rc == 0
- name: delete storage pool
command: "virsh {{ item }}"
loop:
- pool-destroy mirror
- pool-undefine mirror
when: pool_exists.rc == 0
- name: delete mirbr0 bridge network
command: "virsh {{ item }}"
loop:
- net-destroy mirbr0
- net-undefine mirbr0
when: net_exists.rc == 0
- name: delete directory for vm
file:
path: "{{ playbook_dir }}/vm"
state: absent

@ -2,6 +2,7 @@
- name: setup mirror vm
hosts: 127.0.0.1
gather_facts: no
become: yes
tasks:
- name: mirbr0 network exists
command: "virsh net-dumpxml mirbr0"

Loading…
Cancel
Save