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