Compare commits

...

2 Commits

7 changed files with 98 additions and 27 deletions

View File

@ -34,21 +34,19 @@ en1:
- server - server
- datastore - datastore
- swarm - 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: hosts:
pegasus: # jupiter pegasus: # jupiter
ansible_host: 10.42.101.100 ansible_host: 10.42.101.100
skylab_hostname: pegasus.skylab.enp.one skylab_hostname: pegasus.skylab.enp.one
skylab_legacy_names:
- jupiter.net.enp.one
- jupiter.svr.local
skylab_description: Arbiter Node skylab_description: Arbiter Node
skylab_cluster: skylab_cluster:
address: 10.42.101.10/24 address:
access: 10.42.101.10/24
internal: 192.168.42.10/24
interface: interface:
access: bond0 access: bond0
internal: bond0.99 internal: bond0.99
@ -77,9 +75,14 @@ en1:
saturn: # remus saturn: # remus
ansible_host: 10.42.101.110 ansible_host: 10.42.101.110
skylab_hostname: saturn.skylab.enp.one skylab_hostname: saturn.skylab.enp.one
skylab_legacy_names:
- remus.net.enp.one
- remus.svr.local
skylab_description: Operational Node skylab_description: Operational Node
skylab_cluster: skylab_cluster:
address: 10.42.101.11/24 address:
access: 10.42.101.11/24
internal: 192.168.42.20/24
interface: interface:
access: bond0 access: bond0
internal: bond0.99 internal: bond0.99
@ -108,9 +111,14 @@ en1:
orion: # romulus orion: # romulus
ansible_host: 10.42.101.120 ansible_host: 10.42.101.120
skylab_hostname: orion.skylab.enp.one skylab_hostname: orion.skylab.enp.one
skylab_legacy_names:
- romulus.net.enp.one
- romulus.svr.local
skylab_description: Operational Node skylab_description: Operational Node
skylab_cluster: skylab_cluster:
address: 10.42.101.12/24 address:
access: 10.42.101.12/24
internal: 192.168.42.30/24
interface: interface:
access: bond0 access: bond0
internal: bond0.99 internal: bond0.99

View File

@ -59,7 +59,7 @@
when: inventory_hostname != _target_node when: inventory_hostname != _target_node
ansible.builtin.assert: ansible.builtin.assert:
that: 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' - _docker_node_availability | lower == 'active'
fail_msg: >- fail_msg: >-
ERROR: Node '{{ inventory_hostname }}' is already marked as unavailable. All cluster ERROR: Node '{{ inventory_hostname }}' is already marked as unavailable. All cluster
@ -115,15 +115,15 @@
- name: Delete address from node - name: Delete address from node
become: true 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: 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 changed_when: true
- name: Assign address to alt node - name: Assign address to alt node
delegate_to: "{{ _target_alt }}" delegate_to: "{{ _target_alt }}"
become: true 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: 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 changed_when: true

View File

@ -37,12 +37,12 @@
vars: vars:
_cluster_node_ips: [] _cluster_node_ips: []
ansible.builtin.set_fact: 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 }}" loop: "{{ groups.cluster }}"
- name: Remove alternative node IPs - name: Remove alternative node IPs
become: true 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: ansible.builtin.command:
cmd: ip address delete {{ item | ansible.netcommon.ipaddr('host/prefix') }} dev {{ skylab_cluster.interface.access }} cmd: ip address delete {{ item | ansible.netcommon.ipaddr('host/prefix') }} dev {{ skylab_cluster.interface.access }}
changed_when: true changed_when: true
@ -50,7 +50,7 @@
- name: Add node IP - name: Add node IP
become: true 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: 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 changed_when: true

View File

@ -9,12 +9,10 @@
vars: vars:
_hostsfile_lines: [] _hostsfile_lines: []
ansible.builtin.set_fact: ansible.builtin.set_fact:
_hostsfile_lines: "{{ _hostsfile_lines + [item.address + ' ' + 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: "{{ skylab_direct_peers }}" loop: "{{ groups.cluster }}"
loop_control:
label: "{{ item.hostname }}"
- name: Configure directly connected peers - name: Configure local hostsfile
become: true become: true
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: /etc/hosts path: /etc/hosts
@ -24,7 +22,7 @@
loop_control: loop_control:
label: "{{ item.partition(' ')[0] }}" label: "{{ item.partition(' ')[0] }}"
- name: Remove unmanaged peer aliases - name: Remove unmanaged hostsfile entries
become: true become: true
when: "'localhost' not in item and item not in _hostsfile_lines" when: "'localhost' not in item and item not in _hostsfile_lines"
ansible.builtin.lineinfile: ansible.builtin.lineinfile:

View File

@ -14,8 +14,8 @@
ansible.builtin.include_tasks: firewalld.yaml ansible.builtin.include_tasks: firewalld.yaml
- name: Configure hostsfile - name: Configure hostsfile
when: skylab_direct_peers is defined when: "inventory_hostname in groups.cluster"
ansible.builtin.include_tasks: hosts.yaml ansible.builtin.import_tasks: hosts.yaml
- name: Enable tmpfs mount - name: Enable tmpfs mount
become: true become: true

View File

@ -0,0 +1,62 @@
---
- name: Fetch glusterfs plugin state
block:
- name: Fetch glusterfs storage plugin state
ansible.builtin.command:
cmd: docker plugin inspect glusterfs
changed_when: false
register: _docker_glusterfs_storage_plugin_raw
rescue:
- name: Install glusterfs storage plugin
ansible.builtin.command:
cmd: docker plugin install --alias glusterfs mochoa/glusterfs-volume-plugin --grant-all-permissions --disable
changed_when: true
- name: Fetch glusterfs storage plugin state
ansible.builtin.command:
cmd: docker plugin inspect glusterfs
changed_when: false
register: _docker_glusterfs_storage_plugin_raw
- name: Process glusterfs storage plugin config
ansible.builtin.set_fact:
_docker_glusterfs_storage_plugin: "{{ (_docker_glusterfs_storage_plugin_raw.stdout | from_json)[0] }}"
# Note that this might not end up being defined if the plugin has not been configured
- name: Identify plugin server settings
when: item.startswith('SERVERS')
ansible.builtin.set_fact:
_docker_glusterfs_existing_setting: "{{ item }}"
loop: "{{ _docker_glusterfs_storage_plugin.Settings.Env }}"
- name: Determine gluster servers
run_once: true
when: "'datastore' in hostvars[item].skylab_roles | default([])"
vars:
_docker_glusterfs_hostnames: []
ansible.builtin.set_fact:
_docker_glusterfs_hostnames: "{{ _docker_glusterfs_hostnames + [item + '.local'] }}"
loop: "{{ groups.cluster }}"
- name: Determine gluster plugin setting
ansible.builtin.set_fact:
_docker_glusterfs_setting: "SERVERS={{ _docker_glusterfs_hostnames | join(',') }}"
- name: Configure plugin
when: _docker_glusterfs_setting != _docker_glusterfs_existing_setting
block:
- name: Disable plugin
when: _docker_glusterfs_storage_plugin.Enabled
ansible.builtin.command:
cmd: docker plugin disable glusterfs
- name: Set plugin servers setting
changed_when: true
ansible.builtin.command:
cmd: docker plugin set glusterfs {{ _docker_glusterfs_setting }}
register: _docker_glusterfs_set_setting
- name: Enable plugin
when: not _docker_glusterfs_storage_plugin.Enabled or _docker_glusterfs_set_setting.changed | default(false)
ansible.builtin.command:
cmd: docker plugin enable glusterfs

View File

@ -16,3 +16,6 @@
- name: Join server to swarm - name: Join server to swarm
when: _docker_swarm_needs_join when: _docker_swarm_needs_join
ansible.builtin.include_tasks: join.yaml ansible.builtin.include_tasks: join.yaml
- name: Configure gluster storage driver
ansible.builtin.import_tasks: gluster.yaml