skylab
/
skylab-ansible
Archived
2
0
Fork 0

Add install of gluster storage plugin to swarm role

This commit is contained in:
Ethan Paul 2021-11-13 21:09:54 -05:00
parent f178a7bf78
commit eb569c05c7
No known key found for this signature in database
GPG Key ID: 6A337337DF6B5B1A
2 changed files with 65 additions and 0 deletions

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
when: _docker_swarm_needs_join
ansible.builtin.include_tasks: join.yaml
- name: Configure gluster storage driver
ansible.builtin.import_tasks: gluster.yaml