ansible-role-libvirt_kvm/tasks/main.yml
Adrien bd9c69b749
All checks were successful
continuous-integration/drone/push Build is passing
fix lint
2020-06-04 10:59:19 +02:00

114 lines
2.6 KiB
YAML

---
- name: Include vars for {{ ansible_os_family }}
include_vars: "{{ ansible_os_family }}.yml"
- name: "Ensure system is x86_64"
fail:
msg: "qemu-kvm requires a 64bit system architecture for now"
when: "ansible_architecture != 'x86_64'"
- name: "Ensure system is hardware virtualization capability"
fail:
msg: "qemu-kvm requires hypervisor capability"
when: "ansible_virtualization_type != 'kvm'"
- name: Include tasks for {{ ansible_os_family }}
include_tasks: "{{ ansible_os_family }}.yml"
- name: install packages
package:
name: "{{ libvirt_kvm_packages }}"
state: present
update_cache: yes
notify: Restart libvirt
- name: Allow hypervisor in VM
template:
src: kvm.conf.j2
dest: /etc/modprobe.d/kvm.conf
owner: root
group: root
mode: 0644
- name: Install Openvswitch
include_role:
name: openvswitch
# vars:
# openvswitch_brname: "{{ libvirt_brname }}"
when:
- libvirt_openvswitch|bool
register: install_openvswitch
- name: Restart libvirt_kvm after openvswitch installation
service:
name: "{{ libvirt_service }}"
state: restarted
#- name: Add Openvswitch bridge
# openvswitch_bridge:
# bridge: '{{ qemu_default_network_interface }}'
# parent: '{{ openvswitch_interface }}'
# state: present
- name: Enable libvirt deamon
service:
name: "{{ libvirt_service }}"
state: started
enabled: yes
- name: Add defaults networks
virt_net:
command: define
name: '{{ item }}'
xml: '{{ lookup ("template", "networks/{{ item }}.xml.j2") }}'
with_items:
- default
- private
- name: Enable defaults networks on boot
virt_net:
name: '{{ item }}'
autostart: yes
with_items:
- default
- private
- name: Activate defaults networks now if it doesn't already up
virt_net:
name: '{{ item }}'
state: active
with_items:
- default
- private
- name: Add OpenVswitch networks
virt_net:
command: define
name: '{{ item.name }}'
xml: '{{ lookup ("template", "networks/openvswitch.xml.j2") }}'
with_items:
- '{{ virtual_network }}'
when:
- virtual_network is defined
- libvirt_openvswitch|bool
- name: Activate OpenVSwitch networks now if it doesn't already up
virt_net:
name: '{{ item.name }}'
state: active
with_items:
- '{{ virtual_network }}'
when:
- virtual_network is defined
- libvirt_openvswitch|bool
- name: Enable OpenVSwitch networks on boot
virt_net:
name: '{{ item.name }}'
autostart: yes
with_items:
- '{{ virtual_network }}'
when:
- virtual_network is defined
- libvirt_openvswitch|bool