tenks/ansible/schedule.yml
Will Miller 99eaf48098 Persist physnet indices in state file
Instead of overwriting the physnet mappings specified in the Tenks
configuration, create a separate dict that maps physnet names to their
indices. Like physnet_mappings, this will be present for each
hypervisor.
2018-09-14 10:27:21 +00:00

49 lines
1.5 KiB
YAML

---
# Ensure we have facts about all hypervisors before scheduling begins.
- hosts: hypervisors
gather_facts: true
- hosts: localhost
tasks:
- name: Check that all specified node types exist
fail:
msg: >
The non-existent node type {{ item.type }} was specified in
'specs'.
when: item.type not in node_types
loop: "{{ specs }}"
# Creates a dict mapping each hypervisor's hostname to its hostvars, to be
# used during scheduling.
- name: Collect hypervisor hostvars
set_fact:
hypervisor_vars: >-
{{ hypervisor_vars | default({}) | combine({item: hostvars[item]}) }}
loop: "{{ groups['hypervisors'] }}"
- name: Check if an existing state file exists
stat:
path: "{{ state_file_path }}"
register: stat_result
- name: Read existing state from file
include_vars:
file: "{{ state_file_path }}"
name: current_state
when: stat_result.stat.exists
- name: Get updated state
tenks_update_state:
hypervisor_vars: "{{ hypervisor_vars }}"
node_types: "{{ node_types }}"
specs: "{{ specs }}"
state: "{{ current_state | default(omit) }}"
register: new_state
- name: Write new state to file
copy:
# tenks_schedule lookup plugin outputs a dict. Pretty-print this to
# persist it in a YAML file.
content: "{{ new_state.result | to_nice_yaml }}"
dest: "{{ state_file_path }}"