tripleo-quickstart/roles/libvirt/setup/overcloud/tasks/main.yml

118 lines
4.1 KiB
YAML

# Create a libvirt volume pool. This is where we'll be creating
# images for the undercloud and overcloud.
# Note: the virt_pool module is not working properly on rhel-7.2
# https://bugs.launchpad.net/tripleo-quickstart/+bug/1597905
- name: Check volume pool
command: >
virsh pool-uuid "{{ libvirt_volume_pool }}"
register: pool_check
ignore_errors: true
changed_when: false
environment:
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
- name: create the volume pool xml file
template:
src: volume_pool.xml.j2
dest: "{{ working_dir }}/volume_pool.xml"
when: pool_check|failed
- name: Define volume pool
command: "virsh pool-define {{ working_dir }}/volume_pool.xml"
when: pool_check|failed
environment:
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
- name: Start volume pool
virt_pool:
command: start
state: active
name: "{{ libvirt_volume_pool }}"
uri: "{{ libvirt_uri }}"
# In some cases the pool_check can pass and the pool xml config is absent
# In this case it is required to dump the xml and redefine the pool.
- name: ensure tripleo-quickstart volume pool is defined
shell: >
virsh pool-dumpxml {{ libvirt_volume_pool }} |
virsh pool-define /dev/stdin
changed_when: true
environment:
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
- name: Mark volume pool for autostart
virt_pool:
name: "{{ libvirt_volume_pool }}"
autostart: "yes"
uri: "{{ libvirt_uri }}"
- when: overcloud_nodes
block:
# Generate MAC addresses that we'll use for the overcloud nodes.
# By generating these in advance we can populate the
# `instackenv.json` file with MAC addresses without running
# introspection.
- name: get a list of MACs to use
generate_macs:
nodes: "{{ overcloud_nodes }}"
networks: "{{ networks }}"
register: node_mac_map
# Create libvirt volumes for the overcloud hosts.
- name: Check if overcloud volumes exist
command: >
virsh vol-info --pool '{{libvirt_volume_pool}}' '{{item.name}}.qcow2'
register: overcloud_vol_check
ignore_errors: true
environment:
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
with_items: "{{ overcloud_nodes }}"
- name: Create overcloud vm storage
command: >
virsh vol-create-as '{{ libvirt_volume_pool }}'
'{{ item.item.name }}'.qcow2 '{{ flavors[item.item.flavor].disk }}'G
--format qcow2
environment:
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
when: item|failed
with_items: "{{ overcloud_vol_check.results }}"
# Define (but do not start) the overcloud nodes. These will be
# booted later by ironic during the provisioning process.
- name: Define overcloud vms
virt:
name: "{{ item.name }}"
command: define
xml: "{{ lookup('template', 'baremetalvm.xml.j2') }}"
uri: "{{ libvirt_uri }}"
with_items: "{{ overcloud_nodes }}"
# Create additional blockdevices for each objectstorage flavor node
# These are sparse files, not using space if unused
- name: Create additional blockdevice for objectstorage nodes
command: >
dd if=/dev/zero of={{ libvirt_volume_path }}/{{ item[0].name }}_{{ item[1] }}.img bs=1 count=0 seek=1G
when: "{{ flavors[item[0].flavor].extradisks | default(false) }}"
with_nested:
- "{{ overcloud_nodes }}"
- "{{ extradisks_list }}"
- name: Attach additional blockdevices to overcloud objectstorage VMs
command: >
virsh attach-disk --config {{ item[0].name }} {{ libvirt_volume_path }}/{{ item[0].name }}_{{ item[1] }}.img {{ item[1] }}
when: "{{ flavors[item[0].flavor].extradisks | default(false) }}"
with_nested:
- "{{ overcloud_nodes }}"
- "{{ extradisks_list }}"
# Generate the `instackenv.json` configuration file. Note that this
# task *must* occur after the above overcloud tasks, because if
# `overcloud_nodes` is defined the template depends on the
# `node_mac_map` variable.
- name: Write instackenv script
template:
src: "{{ undercloud_instackenv_template }}"
dest: "{{ working_dir }}/instackenv.json"