tenks/ansible/schedule.yml
Mark Goddard 6e2bb04fae Add playbook tags
Allows for easily running specific playbooks.

Change-Id: Ia859238042eb286b61758acd8f99361c10dc0a05
2019-03-27 16:43:13 +00:00

55 lines
1.6 KiB
YAML

---
# Ensure we have facts about all hypervisors before scheduling begins.
- hosts: hypervisors
tags:
- schedule
gather_facts: true
- hosts: localhost
tags:
- schedule
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_name_prefix: "{{ node_name_prefix | default(omit) }}"
node_types: "{{ node_types }}"
specs: "{{ specs }}"
state: "{{ current_state | default(omit) }}"
vol_name_prefix: "{{ vol_name_prefix | 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 }}"