diff --git a/playbooks/node-down.yaml b/playbooks/node-down.yaml index d142c17..2a5e502 100644 --- a/playbooks/node-down.yaml +++ b/playbooks/node-down.yaml @@ -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