| --- |
| # ============LICENSE_START======================================================= |
| # Copyright (C) 2019 The Nordix Foundation. All rights reserved. |
| # ================================================================================ |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| # SPDX-License-Identifier: Apache-2.0 |
| # ============LICENSE_END========================================================= |
| - name: Find node in PDF by node name '{{ vm.key }}' |
| set_fact: |
| hostname: "{{ vm.value }}" |
| node: "{{ nodes | selectattr('name', 'equalto', vm.key) | first }}" |
| |
| - name: List info on pools |
| virt_pool: |
| command: facts |
| uri: "{{ vm_libvirt_uri }}" |
| |
| - name: Set prealloc arg for Debian |
| set_fact: |
| prealloc: "--prealloc-metadata" |
| when: |
| - ansible_os_family == 'Debian' |
| - vm_libvirt_uri == 'qemu:///system' |
| |
| - name: Destroy vm '{{ hostname }}' |
| virt: |
| command: destroy |
| name: "{{ hostname }}" |
| uri: "{{ vm_libvirt_uri }}" |
| ignore_errors: true |
| |
| - name: Undefine vm '{{ hostname }}' |
| virt: |
| command: undefine |
| name: "{{ hostname }}" |
| uri: "{{ vm_libvirt_uri }}" |
| ignore_errors: true |
| |
| - name: Initialize disk information for vm '{{ hostname }}' |
| set_fact: |
| disks: [ ] |
| dev_suffix: "abcdefghijklmnopqrstuvwxyz" |
| |
| - name: Create target device names of all disks for vm '{{ hostname }}' |
| set_fact: |
| disks: "{{ disks + [ disk | combine( { 'dev': 'vd' + dev_suffix[disk_no] } ) ] }}" |
| with_items: |
| - "{{ node.disks }}" |
| loop_control: |
| loop_var: disk |
| index_var: disk_no |
| |
| - name: Setup volumes for vm '{{ hostname }}' |
| include_tasks: create-libvirt-volumes.yml |
| with_items: |
| - "{{ disks }}" |
| loop_control: |
| loop_var: disk |
| |
| - name: Delete logs from previous deployment |
| file: |
| path: "{{ vm_console_log_path }}/" |
| state: absent |
| |
| - name: Create directory for console logs |
| file: |
| path: "{{ vm_console_log_path }}" |
| state: directory |
| mode: 0755 |
| |
| - name: Create vm '{{ hostname }}' |
| virt: |
| command: define |
| name: "{{ hostname }}" |
| uri: "{{ vm_libvirt_uri }}" |
| xml: "{{ lookup('template', 'libvirt-vm.xml.j2') }}" |
| |
| - name: Set virtual IPMI port for '{{ hostname }}' |
| set_fact: |
| virtual_ipmi_port: "{{ ( node.remote_management.port | default(623) | int ) }}" |
| |
| - name: Plug vm '{{ hostname }}' into vbmc on port '{{ virtual_ipmi_port }}' |
| command: "vbmc add {{ hostname }} --libvirt-uri {{ vm_libvirt_uri }} --port {{ virtual_ipmi_port }}" |
| environment: |
| PATH: "{{ engine_venv }}/bin" |
| |
| - name: Start vbmc for '{{ hostname }}' |
| command: "vbmc start {{ hostname }}" |
| environment: |
| PATH: "{{ engine_venv }}/bin" |
| |
| # vim: set ts=2 sw=2 expandtab: |