diff --git a/roles/glusterfs/tasks/main.yml b/roles/glusterfs/tasks/main.yml index c7e526618..dae215814 100644 --- a/roles/glusterfs/tasks/main.yml +++ b/roles/glusterfs/tasks/main.yml @@ -42,8 +42,36 @@ name: "{{ gluster_brick_name }}" brick: "{{ gluster_brick_dir }}" replicas: "{{ groups['gfs-cluster'] | length }}" - cluster: "{{ groups['gfs-cluster'] | map('extract', hostvars, ['ansible_eth0', 'ipv4', 'address']) | join(',') }}" + cluster: "{{ groups['gfs-cluster'] | map('extract', hostvars, ['ip']) | join(',') }}" host: "{{ inventory_hostname }}" force: yes run_once: true +- name: Mount glusterfs to retrieve disk size + mount: + name: "{{ gluster_mount_dir }}" + src: "{{ hostvars[groups['gfs-cluster'][0]]['ip'] }}:/gluster" + fstype: glusterfs + opts: "defaults,_netdev" + state: mounted + when: groups['gfs-cluster'] is defined and inventory_hostname == groups['gfs-cluster'][0] + +- name: Get Gluster disk size + setup: filter=ansible_mounts + register: mounts_data + when: groups['gfs-cluster'] is defined and inventory_hostname == groups['gfs-cluster'][0] + +- name: Set Gluster disk size to variable + set_fact: + gluster_disk_size_gb: "{{ (mounts_data.ansible_facts.ansible_mounts | selectattr('mount', 'equalto', gluster_mount_dir) | map(attribute='size_total') | first | int / (1024*1024*1024)) | int }}" + when: groups['gfs-cluster'] is defined and inventory_hostname == groups['gfs-cluster'][0] + + +- name: Unmount glusterfs + mount: + name: "{{ gluster_mount_dir }}" + fstype: glusterfs + src: "{{ hostvars[groups['gfs-cluster'][0]]['ip'] }}:/gluster" + state: unmounted + when: groups['gfs-cluster'] is defined and inventory_hostname == groups['gfs-cluster'][0] + diff --git a/roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-endpoint.json.j2 b/roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-endpoint.json.j2 index 93610dcff..2b77036be 100644 --- a/roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-endpoint.json.j2 +++ b/roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-endpoint.json.j2 @@ -2,15 +2,14 @@ "kind": "Endpoints", "apiVersion": "v1", "metadata": { - "name": "glusterfs-cluster" + "name": "glusterfs" }, "subsets": [ + {% for host in groups['gfs-cluster'] %} { "addresses": [ - { - {% for host in groups['gfs-cluster'] %} - "ip": "{{hostvars[host]['ansible_eth0']['ipv4']['address']}}"{%- if not loop.last %}, {% endif -%} - {% endfor %} + { + "ip": "{{hostvars[host]['ip']}}" } ], "ports": [ @@ -18,7 +17,8 @@ "port": 1 } ] - } + }{%- if not loop.last %}, {% endif -%} + {% endfor %} ] } diff --git a/roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-pv.yml b/roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-pv.yml.j2 similarity index 64% rename from roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-pv.yml rename to roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-pv.yml.j2 index 463939093..4eef00535 100644 --- a/roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-pv.yml +++ b/roles/kubernetes-apps/ansible/templates/glusterfs-kubernetes-pv.yml.j2 @@ -1,8 +1,10 @@ apiVersion: v1 kind: PersistentVolume metadata: - name: gluster-default-volume + name: glusterfs spec: + capacity: + storage: "{{ hostvars[groups['gfs-cluster'][0]].gluster_disk_size_gb }}Gi" accessModes: - ReadWriteMany glusterfs: