tenks/ansible/schedule.yml
Mark Goddard 8df4a68fb1 Fix node scheduling with pipe in hostvars
If Ansible hostvars contain a pipe (|) character, this can cause
problems during scheduling as Ansible fails during Jinja templating.
This is probably a bug in Ansible/Jinja.

The particular case where this was hit was when using screen, the
TERMCAP environment variable gets set to something beginning with
'SC|screen|VT'.

This change addresses the issue by moving the capture of hostvars inside
the tenks_update_state action plugin rather than evaluating them in a
playbook.

Change-Id: Ibef91d9ef499c8741b61a170672a23f530a600bb
2020-03-20 10:59:30 +00:00

48 lines
1.4 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 }}"
- 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:
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.
# NOTE(mgoddard): Use .get to avoid a nasty error in ansible-lint
# (cannot represent an object).
content: "{{ new_state.get('result') | to_nice_yaml }}"
dest: "{{ state_file_path }}"