cc3d27e2e1
The seed VM will fail to provision if the Ansible control host and the seed hypervisor are not the same hosts. This is because Kayobe creates the seed-vm-user-data file on the seed-hypervisor host. It then invokes the jriguera.configdrive role which uses a copy task without remote_src, which fails to find the source file locally on the Ansible control host. Instead we create a local temporary file for seed VM user data. Change-Id: Iabbe4c624b9ad02bb82c323070f99c16e5822966 Story: 2007530 Task: 39338
136 lines
4.8 KiB
YAML
136 lines
4.8 KiB
YAML
---
|
|
- name: Ensure that the seed VM configdrive exists
|
|
hosts: seed-hypervisor
|
|
vars:
|
|
seed_host: "{{ groups['seed'][0] }}"
|
|
pre_tasks:
|
|
- name: Verify the seed host exists in the Ansible inventory
|
|
fail:
|
|
msg: >
|
|
There should be exactly one host in the seed group. There are
|
|
currently {{ groups['seed'] | length }}.
|
|
when: groups['seed'] | length != 1
|
|
|
|
- name: Ensure the image cache directory exists
|
|
file:
|
|
path: "{{ image_cache_path }}"
|
|
state: directory
|
|
owner: "{{ ansible_user_uid }}"
|
|
group: "{{ ansible_user_gid }}"
|
|
become: True
|
|
|
|
- name: Create a temporary user data file locally
|
|
tempfile:
|
|
state: file
|
|
register: seed_user_data_file
|
|
delegate_to: localhost
|
|
|
|
# The user data script is used to bring up the network interfaces that will
|
|
# be configured by metadata in the configdrive. For some reason resolv.conf
|
|
# gets configured with 660 permissions, so fix that here also.
|
|
- name: Ensure the user data file exists
|
|
copy:
|
|
content: |
|
|
#!/bin/bash
|
|
{% for interface in hostvars[seed_host].network_interfaces | map('net_interface', seed_host) %}
|
|
# Bounce {{ interface }}.
|
|
ifdown {{ interface }}
|
|
ifup {{ interface }}
|
|
{% endfor %}
|
|
# Fix permissions of resolv.conf.
|
|
chmod 644 /etc/resolv.conf
|
|
dest: "{{ seed_user_data_file.path }}"
|
|
delegate_to: localhost
|
|
|
|
roles:
|
|
- role: jriguera.configdrive
|
|
# For now assume the VM OS family is the same as the hypervisor's.
|
|
configdrive_os_family: "{{ ansible_os_family }}"
|
|
configdrive_uuid: "{{ seed_host | to_uuid }}"
|
|
configdrive_fqdn: "{{ seed_host }}"
|
|
configdrive_name: "{{ seed_host }}"
|
|
configdrive_ssh_public_key: "{{ lookup('file', ssh_public_key_path) }}"
|
|
configdrive_config_dir: "{{ image_cache_path }}"
|
|
configdrive_volume_path: "{{ image_cache_path }}"
|
|
configdrive_config_dir_delete: True
|
|
configdrive_resolv:
|
|
domain: "{{ hostvars[seed_host].resolv_domain | default }}"
|
|
search: "{{ hostvars[seed_host].resolv_search | default }}"
|
|
dns: "{{ hostvars[seed_host].resolv_nameservers | default([]) }}"
|
|
configdrive_network_device_list: >
|
|
{{ hostvars[seed_host].network_interfaces |
|
|
map('net_configdrive_network_device', seed_host) |
|
|
list }}
|
|
configdrive_config_user_data_path: "{{ seed_user_data_file.path }}"
|
|
|
|
tasks:
|
|
- name: Set a fact containing the configdrive image path
|
|
set_fact:
|
|
seed_vm_configdrive_path: "{{ image_cache_path }}/{{ seed_host }}.iso"
|
|
|
|
- name: Ensure configdrive is decoded and decompressed
|
|
shell: >
|
|
base64 -d {{ image_cache_path }}/{{ seed_host | to_uuid }}.gz
|
|
| gunzip
|
|
> {{ seed_vm_configdrive_path }}
|
|
|
|
- name: Ensure unnecessary files are removed
|
|
file:
|
|
path: "{{ item }}"
|
|
state: absent
|
|
with_items:
|
|
- "{{ image_cache_path }}/{{ seed_host | to_uuid }}.gz"
|
|
|
|
- name: Ensure unnecessary local files are removed
|
|
file:
|
|
path: "{{ item }}"
|
|
state: absent
|
|
with_items:
|
|
- "{{ seed_user_data_file.path }}"
|
|
delegate_to: localhost
|
|
|
|
- name: Ensure that the seed VM is provisioned
|
|
hosts: seed-hypervisor
|
|
vars:
|
|
seed_host: "{{ groups['seed'][0] }}"
|
|
pre_tasks:
|
|
- name: Check the size of the configdrive image
|
|
stat:
|
|
path: "{{ seed_vm_configdrive_path }}"
|
|
get_checksum: False
|
|
get_md5: False
|
|
mime: False
|
|
register: stat_result
|
|
|
|
roles:
|
|
- role: stackhpc.libvirt-vm
|
|
seed_vm_configdrive_volume:
|
|
name: "{{ hostvars[seed_host].seed_vm_name }}-configdrive"
|
|
pool: "{{ hostvars[seed_host].seed_vm_pool }}"
|
|
# Round size up to next multiple of 4096.
|
|
capacity: "{{ (stat_result.stat.size + 4095) // 4096 * 4096 }}"
|
|
device: "cdrom"
|
|
format: "raw"
|
|
image: "{{ seed_vm_configdrive_path }}"
|
|
libvirt_vm_image_cache_path: "{{ image_cache_path }}"
|
|
libvirt_vms:
|
|
- name: "{{ hostvars[seed_host].seed_vm_name }}"
|
|
memory_mb: "{{ hostvars[seed_host].seed_vm_memory_mb }}"
|
|
vcpus: "{{ hostvars[seed_host].seed_vm_vcpus }}"
|
|
volumes: "{{ hostvars[seed_host].seed_vm_volumes + [seed_vm_configdrive_volume] }}"
|
|
interfaces: >
|
|
{{ hostvars[seed_host].network_interfaces | map('net_libvirt_vm_network') | list }}
|
|
console_log_enabled: true
|
|
become: True
|
|
|
|
tasks:
|
|
- name: Wait for SSH access to the seed VM
|
|
local_action:
|
|
module: wait_for
|
|
host: "{{ hostvars[seed_host].ansible_host }}"
|
|
port: 22
|
|
state: started
|
|
# NOTE: Ensure we exceed the 5 minute DHCP timeout of the eth0
|
|
# interface if necessary.
|
|
timeout: 360
|