|
| 1 | +--- |
| 2 | +# Copyright (c) 2024 Oracle and/or its affiliates. |
| 3 | +# This software is made available to you under the terms of the Universal Permissive License (UPL), Version 1.0. |
| 4 | +# The Universal Permissive License (UPL), Version 1.0 (see COPYING or https://oss.oracle.com/licenses/upl) |
| 5 | +# See LICENSE.TXT for details. |
| 6 | + |
| 7 | +- name: Install a KVM server |
| 8 | + hosts: kvm-server |
| 9 | + vars_files: |
| 10 | + - default_vars.yml |
| 11 | + become: true |
| 12 | + |
| 13 | + tasks: |
| 14 | + |
| 15 | + - name: Install Oracle Linux 8 virtualization packages |
| 16 | + ansible.builtin.dnf: |
| 17 | + name: |
| 18 | + - "@virt" |
| 19 | + - virt-install |
| 20 | + - virt-viewer |
| 21 | + - containers-common |
| 22 | + - cockpit |
| 23 | + - cockpit-machines |
| 24 | + state: present |
| 25 | + when: ansible_distribution == 'OracleLinux' and ansible_distribution_major_version == '8' |
| 26 | + |
| 27 | + - name: Install Oracle Linux 9 virtualization packages |
| 28 | + ansible.builtin.dnf: |
| 29 | + name: |
| 30 | + - qemu-kvm |
| 31 | + - libvirt |
| 32 | + - virt-install |
| 33 | + - virt-viewer |
| 34 | + - containers-common |
| 35 | + - cockpit |
| 36 | + - cockpit-machines |
| 37 | + state: present |
| 38 | + when: ansible_distribution == 'OracleLinux' and ansible_distribution_major_version == '9' |
| 39 | + |
| 40 | + - name: Start and enable Oracle Linux 8 monolithic virtualization services |
| 41 | + ansible.builtin.systemd: |
| 42 | + state: started |
| 43 | + name: libvirtd.service |
| 44 | + enabled: true |
| 45 | + when: ansible_distribution == 'OracleLinux' and ansible_distribution_major_version == '8' |
| 46 | + |
| 47 | + - name: Start and enable Oracle Linux 9 modular 'ro' virtualization services |
| 48 | + ansible.builtin.systemd: |
| 49 | + state: started |
| 50 | + name: "virt{{ item }}d-ro.socket" |
| 51 | + enabled: true |
| 52 | + loop: |
| 53 | + - qemu |
| 54 | + - network |
| 55 | + - nodedev |
| 56 | + - nwfilter |
| 57 | + - secret |
| 58 | + - storage |
| 59 | + - interface |
| 60 | + - proxy |
| 61 | + when: ansible_distribution == 'OracleLinux' and ansible_distribution_major_version == '9' |
| 62 | + |
| 63 | + - name: Start and enable Oracle Linux 9 modular 'admin' virtualization services |
| 64 | + ansible.builtin.systemd: |
| 65 | + state: started |
| 66 | + name: "virt{{ item }}d-admin.socket" |
| 67 | + enabled: true |
| 68 | + loop: |
| 69 | + - qemu |
| 70 | + - network |
| 71 | + - nodedev |
| 72 | + - nwfilter |
| 73 | + - secret |
| 74 | + - storage |
| 75 | + - interface |
| 76 | + - proxy |
| 77 | + when: ansible_distribution == 'OracleLinux' and ansible_distribution_major_version == '9' |
| 78 | + |
| 79 | + - name: Start and enable cockpit |
| 80 | + ansible.builtin.systemd: |
| 81 | + state: started |
| 82 | + name: cockpit.socket |
| 83 | + enabled: true |
| 84 | + |
| 85 | + - name: Open firewall for cockpit and virsh |
| 86 | + ansible.posix.firewalld: |
| 87 | + zone: public |
| 88 | + service: "{{ item }}" |
| 89 | + permanent: true |
| 90 | + state: enabled |
| 91 | + immediate: true |
| 92 | + loop: |
| 93 | + - libvirt |
| 94 | + - libvirt-tls |
| 95 | + |
| 96 | + - name: Add user to libvirt and qemu group |
| 97 | + ansible.builtin.user: |
| 98 | + name: "{{ username }}" |
| 99 | + groups: libvirt,qemu |
| 100 | + append: true |
| 101 | + |
| 102 | + - name: Reset ssh connection to allow user changes to affect 'current login user' |
| 103 | + ansible.builtin.meta: reset_connection |
| 104 | + |
| 105 | + # - name: Deploy VM1 |
| 106 | + # vars: |
| 107 | + # base_image_name: "{{ ol8_base_image_name }}" |
| 108 | + # base_image_url: "{{ ol8_base_image_url }}" |
| 109 | + # base_image_sha: "{{ ol8_base_image_sha }}" |
| 110 | + # vm_name: ol8-dev |
| 111 | + # ansible.builtin.import_tasks: provision_kvm_vm.yml |
| 112 | + # when: create_vm |
| 113 | + |
| 114 | + # - name: Deploy VM2 |
| 115 | + # vars: |
| 116 | + # base_image_name: "{{ ol9_base_image_name }}" |
| 117 | + # base_image_url: "{{ ol9_base_image_url }}" |
| 118 | + # base_image_sha: "{{ ol9_base_image_sha }}" |
| 119 | + # vm_name: ol9-dev |
| 120 | + # ansible.builtin.import_tasks: provision_kvm_vm.yml |
| 121 | + # when: create_vm |
0 commit comments