diff --git a/inventory.yaml b/inventory.yaml index 54e2cf1..cd8b090 100644 --- a/inventory.yaml +++ b/inventory.yaml @@ -34,21 +34,19 @@ en1: - server - datastore - swarm - skylab_direct_peers: - - hostname: pegasus.local jupiter.svr.local - address: 192.168.42.10 - - hostname: saturn.local remus.svr.local - address: 192.168.42.20 - - hostname: orion.local - address: 192.168.42.30 hosts: pegasus: # jupiter ansible_host: 10.42.101.100 skylab_hostname: pegasus.skylab.enp.one + skylab_legacy_names: + - jupiter.net.enp.one + - jupiter.svr.local skylab_description: Arbiter Node skylab_cluster: - address: 10.42.101.10/24 + address: + access: 10.42.101.10/24 + internal: 192.168.42.10/24 interface: access: bond0 internal: bond0.99 @@ -77,9 +75,14 @@ en1: saturn: # remus ansible_host: 10.42.101.110 skylab_hostname: saturn.skylab.enp.one + skylab_legacy_names: + - remus.net.enp.one + - remus.svr.local skylab_description: Operational Node skylab_cluster: - address: 10.42.101.11/24 + address: + access: 10.42.101.11/24 + internal: 192.168.42.20/24 interface: access: bond0 internal: bond0.99 @@ -108,9 +111,14 @@ en1: orion: # romulus ansible_host: 10.42.101.120 skylab_hostname: orion.skylab.enp.one + skylab_legacy_names: + - romulus.net.enp.one + - romulus.svr.local skylab_description: Operational Node skylab_cluster: - address: 10.42.101.12/24 + address: + access: 10.42.101.12/24 + internal: 192.168.42.30/24 interface: access: bond0 internal: bond0.99 diff --git a/playbooks/node-down.yaml b/playbooks/node-down.yaml index 2165d66..34fe234 100644 --- a/playbooks/node-down.yaml +++ b/playbooks/node-down.yaml @@ -59,7 +59,7 @@ when: inventory_hostname != _target_node ansible.builtin.assert: that: - - skylab_cluster.address | ansible.netcommon.ipaddr('address') in _node_addresses + - skylab_cluster.address.access | ansible.netcommon.ipaddr('address') in _node_addresses - _docker_node_availability | lower == 'active' fail_msg: >- ERROR: Node '{{ inventory_hostname }}' is already marked as unavailable. All cluster @@ -115,15 +115,15 @@ - name: Delete address from node become: true - when: skylab_cluster.address | ansible.netcommon.ipaddr('address') in _node_addresses + when: skylab_cluster.address.access | ansible.netcommon.ipaddr('address') in _node_addresses ansible.builtin.command: - cmd: ip address delete {{ skylab_cluster.address | ansible.netcommon.ipaddr('host/prefix') }} dev {{ skylab_cluster.interface.access }} + cmd: ip address delete {{ skylab_cluster.address.access | ansible.netcommon.ipaddr('host/prefix') }} dev {{ skylab_cluster.interface.access }} changed_when: true - name: Assign address to alt node delegate_to: "{{ _target_alt }}" become: true - when: skylab_cluster.address | ansible.netcommon.ipaddr('address') not in hostvars[_target_alt]._node_addresses + when: skylab_cluster.address.access | ansible.netcommon.ipaddr('address') not in hostvars[_target_alt]._node_addresses ansible.builtin.command: - cmd: ip address add {{ skylab_cluster.address | ansible.netcommon.ipaddr('host/prefix') }} dev {{ hostvars[_target_alt].skylab_cluster.interface.access }} + cmd: ip address add {{ skylab_cluster.address.access | ansible.netcommon.ipaddr('host/prefix') }} dev {{ hostvars[_target_alt].skylab_cluster.interface.access }} changed_when: true diff --git a/playbooks/node-up.yaml b/playbooks/node-up.yaml index 9b1a020..a10cee6 100644 --- a/playbooks/node-up.yaml +++ b/playbooks/node-up.yaml @@ -37,12 +37,12 @@ vars: _cluster_node_ips: [] ansible.builtin.set_fact: - _cluster_node_ips: "{{ _cluster_node_ips + [hostvars[item].skylab_cluster.address | ansible.netcommon.ipaddr('host/prefix')] }}" + _cluster_node_ips: "{{ _cluster_node_ips + [hostvars[item].skylab_cluster.address.access | 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')) + when: item in _cluster_node_ips and item != (skylab_cluster.address.access | 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 @@ -50,7 +50,7 @@ - name: Add node IP become: true - when: skylab_cluster.address | ansible.netcommon.ipaddr('host/prefix') not in _node_addresses + when: skylab_cluster.address.access | 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 }} + cmd: ip address add {{ skylab_cluster.address.access | ansible.netcommon.ipaddr('host/prefix') }} dev {{ skylab_cluster.interface.access }} changed_when: true diff --git a/roles/server/tasks/hosts.yaml b/roles/server/tasks/hosts.yaml index 27823d2..920c6c1 100644 --- a/roles/server/tasks/hosts.yaml +++ b/roles/server/tasks/hosts.yaml @@ -9,12 +9,10 @@ vars: _hostsfile_lines: [] ansible.builtin.set_fact: - _hostsfile_lines: "{{ _hostsfile_lines + [item.address + ' ' + item.hostname] }}" - loop: "{{ skylab_direct_peers }}" - loop_control: - label: "{{ item.hostname }}" + _hostsfile_lines: "{{ _hostsfile_lines + [hostvars[item].skylab_cluster.address.internal | ansible.netcommon.ipaddr('address') + ' ' + item + '.local ' + hostvars[item].skylab_legacy_names | default([]) | join(' ')] }}" + loop: "{{ groups.cluster }}" -- name: Configure directly connected peers +- name: Configure local hostsfile become: true ansible.builtin.lineinfile: path: /etc/hosts @@ -24,7 +22,7 @@ loop_control: label: "{{ item.partition(' ')[0] }}" -- name: Remove unmanaged peer aliases +- name: Remove unmanaged hostsfile entries become: true when: "'localhost' not in item and item not in _hostsfile_lines" ansible.builtin.lineinfile: diff --git a/roles/server/tasks/main.yaml b/roles/server/tasks/main.yaml index 20114e9..4148cb4 100644 --- a/roles/server/tasks/main.yaml +++ b/roles/server/tasks/main.yaml @@ -14,8 +14,8 @@ ansible.builtin.include_tasks: firewalld.yaml - name: Configure hostsfile - when: skylab_direct_peers is defined - ansible.builtin.include_tasks: hosts.yaml + when: "inventory_hostname in groups.cluster" + ansible.builtin.import_tasks: hosts.yaml - name: Enable tmpfs mount become: true