skylab
/
skylab-ansible
Archived
2
0
Fork 0

Fix variable scoping in node-down playbook

This commit is contained in:
Ethan Paul 2021-10-28 00:35:19 -04:00
parent 8f2ffd6619
commit 7ea4d070ee
No known key found for this signature in database
GPG Key ID: 6A337337DF6B5B1A
1 changed files with 9 additions and 11 deletions

View File

@ -2,18 +2,16 @@
- name: Check cluster state
hosts: cluster
any_errors_fatal: true
vars_prompt:
- name: skylab_node_down
prompt: "Select node to offline (one of: {{ groups.cluster | join(', ') }})"
private: false
tasks:
- name: Validate user input
run_once: true
ansible.builtin.assert:
that:
- skylab_node_down in groups.cluster
- node is defined
- node in groups.cluster
fail_msg: >-
ERROR: Host '{{ skylab_node_down }}' is not a valid cluster node (one
of: {{ groups.cluster | join(', ') }})
ERROR: Please set the 'node' variable to the cluster host to offline
(one of: {{ groups.cluster | join(', ') }})
- name: Fetch node swarm ID
ansible.builtin.command:
@ -29,15 +27,15 @@
- name: Set common facts
ansible.builtin.set_fact:
_target_node: "{{ skylab_node_down }}"
_target_node: "{{ node }}"
_docker_node_id: "{{ _docker_node_id_raw.stdout.strip() }}"
_docker_node_availability: "{{ _docker_node_availability_raw.stdout.strip() }}"
# Use the next host in the group, unless that would exceed the length of the group,
# in which case use the first host in the group
_target_alt: >-
{{ groups.cluster[
lookup('ansible.utils.index_of', groups.cluster, 'eq', skylab_node_down) + 1
if (lookup('ansible.utils.index_of', groups.cluster, 'eq', skylab_node_down) + 1) < (groups.cluster | length)
lookup('ansible.utils.index_of', groups.cluster, 'eq', node) + 1
if (lookup('ansible.utils.index_of', groups.cluster, 'eq', node) + 1) < (groups.cluster | length)
else 0]
}}
@ -68,7 +66,7 @@
nodes must be available before a new node can be moved to unavailable status.
- name: Offline node
hosts: "{{ skylab_node_down }}"
hosts: "{{ node }}"
tasks:
- name: Migrate services off target node
when: _needs_docker_migration