skylab
/
skylab-ansible
Archived
2
0
Fork 0

Add playbook for restoring offline'd node

This commit is contained in:
Ethan Paul 2021-11-11 00:34:05 -05:00
parent 776e35f1a3
commit 20450332d4
No known key found for this signature in database
GPG Key ID: 6A337337DF6B5B1A
1 changed files with 56 additions and 0 deletions

56
playbooks/node-up.yaml Normal file
View File

@ -0,0 +1,56 @@
---
- name: Online nodes
hosts: cluster
vars_prompt:
- name: skylab_datastore_encryption_password
prompt: Enter datastore block decryption password
private: true
roles:
- role: datastore
when: "'datastore' in skylab_roles | default([])"
tasks:
- name: Fetch node swarm ID
ansible.builtin.command:
cmd: !unsafe docker info --format '{{ .Swarm.NodeID}}'
changed_when: false
register: _docker_node_id_raw
- name: Update node availability
vars:
ansible_python_interpreter: "{{ skylab_state_dir }}/ansible-runtime/bin/python"
community.docker.docker_node:
availability: active
hostname: "{{ _docker_node_id_raw.stdout.strip() }}"
- name: Determine node addresses
vars:
_node_addresses:
- "{{ lookup('vars', 'ansible_' + skylab_cluster.interface.access).ipv4.address | ansible.netcommon.ipaddr('host/prefix') }}"
ansible.builtin.set_fact:
_node_addresses: "{{ _node_addresses + [item.address | ansible.netcommon.ipaddr('host/prefix')] }}"
loop: "{{ lookup('vars', 'ansible_' + skylab_cluster.interface.access).ipv4_secondaries }}"
loop_control:
label: "{{ item.address }}"
- name: Determine cluster access addresses
run_once: true
vars:
_cluster_node_ips: []
ansible.builtin.set_fact:
_cluster_node_ips: "{{ _cluster_node_ips + [hostvars[item].skylab_cluster.address | ansible.netcommon.ipaddr('host/prefix')] }}"
loop: "{{ groups.cluster }}"
- name: Remove alternative node IPs
become: true
when: item in _cluster_node_ips and item != (skylab_cluster.address | ansible.netcommon.ipaddr('host/prefix'))
ansible.builtin.command:
cmd: ip address delete {{ item | ansible.netcommon.ipaddr('host/prefix') }} dev {{ skylab_cluster.interface.access }}
changed_when: true
loop: "{{ _node_addresses }}"
- name: Add node IP
become: true
when: skylab_cluster.address | ansible.netcommon.ipaddr('host/prefix') not in _node_addresses
ansible.builtin.command:
cmd: ip address add {{ skylab_cluster.address | ansible.netcommon.ipaddr('host/prefix') }} dev {{ skylab_cluster.interface.access }}
changed_when: true