kayobe/ansible/compute-node-flavors.yml
2017-08-07 12:08:08 +00:00

86 lines
3.3 KiB
YAML

---
# This playbook queries the bare metal compute node inventory in ironic and
# creates flavors in nova for each unique combination of scheduling properties
# (ram, disk, cpus). More complex flavor registration must currently be
# performed manually.
- name: Ensure baremetal compute node flavors are registered in nova
hosts: controllers[0]
vars:
venv: "{{ virtualenv_path }}/shade"
flavor_base_name: baremetal-
roles:
- role: stackhpc.os-openstackclient
os_openstackclient_venv: "{{ venv }}"
tasks:
- name: Get a list of ironic nodes
shell: >
source {{ venv }}/bin/activate &&
openstack baremetal node list --fields name extra properties -f json
register: ironic_node_list
changed_when: False
environment: "{{ openstack_auth_env }}"
- name: Get a list of nova flavors
shell: >
source {{ venv }}/bin/activate &&
openstack flavor list -f json -c Name -c RAM -c VCPUs -c Disk
register: nova_flavor_list
changed_when: False
environment: "{{ openstack_auth_env }}"
- name: Set facts containing the ironic nodes and nova flavors
set_fact:
ironic_nodes: "{{ ironic_node_list.stdout | from_json }}"
ironic_node_flavor_properties: []
existing_nova_flavors: "{{ nova_flavor_list.stdout | from_json }}"
relevant_existing_flavors: []
os_flavors: []
# Build a list of nodes' flavor-relevant properties.
- name: Set a fact containing the ironic node properties
set_fact:
# Extra_specs required for CPU architecture but not currently supported
# by ansible. Will be added in 2.3.
# At that point, add "'cpu_arch': item.Properties.cpu_arch,".
ironic_node_flavor_properties: >
{{ ironic_node_flavor_properties +
[{'vcpus': item.Properties.cpus | int,
'ram': item.Properties.memory_mb | int,
'disk': item.Properties.local_gb | int}] }}
with_items: "{{ ironic_nodes }}"
# Build a list of flavors with the flavor base name, in the same format
# as the ironic node flavor properties list so that they can be compared.
- name: Set a fact containing the relevant nova flavors
set_fact:
relevant_existing_flavors: >
{{ relevant_existing_flavors +
[{'vcpus': item.VCPUs | int,
'ram': item.RAM | int,
'disk': item.Disk | int}] }}
with_items: "{{ existing_nova_flavors }}"
when: "{{ item.Name.startswith(flavor_base_name) }}"
# Build a list of nova flavors to create. Here we offset the flavor name
# index by the length of the relevant existing flavor list. Note that this
# won't work for a list of names other than 0 to N-1.
- name: Set a fact containing a list of flavors to register in nova
set_fact:
os_flavors: >
{{ os_flavors +
[item.1 | combine({'name': flavor_base_name ~ (item.0 + relevant_existing_flavors | length)})] }}
with_indexed_items: >
{{ ironic_node_flavor_properties |
unique |
difference(relevant_existing_flavors) |
sort }}
# Register the new flavors.
- include_role:
role: stackhpc.os-flavors
os_flavors_venv: "{{ venv }}"
os_flavors_auth_type: "{{ openstack_auth_type }}"
os_flavors_auth: "{{ openstack_auth }}"