diff --git a/roles/backend_setup/tasks/cache_setup.yml b/roles/backend_setup/tasks/cache_setup.yml index 25da98c..cc88683 100644 --- a/roles/backend_setup/tasks/cache_setup.yml +++ b/roles/backend_setup/tasks/cache_setup.yml @@ -6,121 +6,62 @@ # Extend the existing volume group with the SSD (assuming SSD is used for # caching) -- name: Check if cachepool exists - shell: "lvs --options 'lv_attr' -a --noheadings {{item.vgname}}/{{item.cachelvname}}| sed 's/^ *//;s/$//'" - register: checkpool_attrs - with_items: "{{ gluster_infra_cache_vars }}" - -- name: Check if cachepool-metadata exists - shell: "lvs --options 'lv_attr' -a --noheadings {{item.vgname}}/{{item.cachelvname}}_cmeta| sed 's/^ *//;s/$//'" - register: checkpoolmeta_attrs - with_items: "{{ gluster_infra_cache_vars }}" - -- name: Check if logical data volume exists - shell: lvs -a --options 'lv_attr' --noheading {{item.vgname}}/{{ item.cachetarget | default(item.cachethinpoolname) }} | sed 's/^ *//;s/$//' - register: datapool_attrs - with_items: "{{ gluster_infra_cache_vars }}" - -- name: Check if logical volume exists and is backed by the cache pool - shell: > - lvs -a --options 'data_lv,pool_lv' --separator "|" --noheadings {{item.vgname}}/{{item.cachetarget | default(item.cachethinpoolname)}} 2>/dev/null| - awk -F '|' '{ gsub(/^\s*\[/,"",$1);gsub(/\]\|?$/,"",$1);if(length($2)>0){ print "echo "$2}else if(length($1)>0){ print "lvs -a --noheadings --options 'pool_lv' {{item.vgname}}/"$1}}'| - bash|sed 's/^ *//;s/$//' - register: datapoolcache_attrs +- name: Extend volume group + lvg: + state: present + vg: "{{ item.vgname }}" + pvs: "{{ item.cachedisk }}" + pv_options: "--dataalignment 256K" with_items: "{{ gluster_infra_cache_vars }}" - name: Change attributes of LV lvol: - state: present - vg: "{{ item.0.vgname }}" - thinpool: "{{ item.0.cachetarget | default(item.0.cachethinpoolname) }}" - opts: " --zero n " - loop: "{{ ((gluster_infra_cache_vars is not none and gluster_infra_cache_vars) or default([])) | zip(((datapool_attrs is not none and datapool_attrs.results) or default([]))) | list }}" - when: item.1.stdout is defined and item.1.stdout|length>0 - -- include_tasks: get_vg_groupings.yml - vars: - volume_groups: >- - {%- set output=[] -%} - {%- for cnf in gluster_infra_cache_vars -%} - {%- if cnf is defined and cnf is not none and cnf.vgname is defined - and (cnf.cachedisk is defined or cnf.meta_pvs is defined) - -%} - {{- output.append({"vgname": cnf.vgname, "pvname": (cnf.cachedisk|default('') ~ ',' ~ (cnf.meta_pvs|default(''))).split(',') | select | list | unique | join(',')}) -}} - {%- endif -%} - {%- endfor -%} - {{- output | to_json -}} - when: gluster_infra_cache_vars is defined and gluster_infra_cache_vars is not none and gluster_infra_cache_vars|length >0 - -- name: Make sure meta and cache pvs exists in volume group - register: gluster_changed_vgs - lvg: - state: present - vg: "{{ (item.value | first).vgname }}" - pvs: "{{ item.value | json_query('[].pvname') | unique | join(',') }}" - pv_options: "--dataalignment 256K" - loop: "{{ gluster_volumes_by_groupname | dict2items }}" - loop_control: - index_var: index - when: > - gluster_volumes_by_groupname is defined and gluster_volumes_by_groupname is not none and gluster_volumes_by_groupname|length >0 - and item.value|length>0 - -- name: update LVM fact's - setup: - filter: 'ansible_lvm' - when: gluster_changed_vgs.changed - + state: present + vg: "{{ item.vgname }}" + thinpool: "{{ item.cachethinpoolname }}" + opts: " --zero n " + with_items: "{{ gluster_infra_cache_vars }}" -- name: Create metadata LV for cache +- name: Create LV for cache lvol: - state: present - vg: "{{ item.0.vgname }}" - lv: "{{ item.0.cachemetalvname | default(item.0.cachelvname ~ '_meta') }}" - size: "{{ item.0.cachemetalvsize }}" - pvs: "{{ ((item.0.meta_pvs is defined and item.0.meta_pvs) or item.0.cachedisk) | default('') }}" - opts: "{{ ((item.0.meta_opts is defined and item.0.meta_opts) or item.0.opts) | default('') }}" - loop: "{{ ((gluster_infra_cache_vars is not none and gluster_infra_cache_vars) or default([])) | zip(((checkpoolmeta_attrs is not none and checkpoolmeta_attrs.results) or default([])))| list }}" - when: item.1.stdout is not defined or item.1.stdout.find('e') != 0 + state: present + vg: "{{ item.vgname }}" + lv: "{{ item.cachelvname }}" + size: "{{ item.cachelvsize }}" + with_items: "{{ gluster_infra_cache_vars }}" -- name: Create LV for cache +- name: Create metadata LV for cache lvol: - state: present - shrink: false - vg: "{{ item.0.vgname }}" - lv: "{{ item.0.cachelvname }}" - size: "{{ item.0.cachelvsize }}" - pvs: "{{ item.0.cachedisk | default('') }}" - opts: "{{ item.0.opts | default('') }}" - #errors throw when trying to modify an existing cachepool attached to a LV - #Operation not permitted on hidden LV ans_vg/cache-ans_thinpool2. - #Sorry, no shrinking of cache-ans_thinpool3 without force=yes. - when: item.1.stdout.find('C') != 0 - loop: "{{ ((gluster_infra_cache_vars is not none and gluster_infra_cache_vars) or default([])) | zip(((checkpool_attrs is not none and checkpool_attrs.results) or default([]))) | list }}" + state: present + vg: "{{ item.vgname }}" + lv: "{{ item.cachemetalvname }}" + size: "{{ item.cachemetalvsize }}" + with_items: "{{ gluster_infra_cache_vars }}" + when: item.cachemetalvname is defined -#Command on LV ans_vg/cache-ans_thinpool2 does not accept LV type cachepool - name: Convert logical volume to a cache pool LV command: > - lvconvert -y --type cache-pool - {% if item.0.cachemetalvname is defined %} - --poolmetadata {{ item.0.vgname }}/{{ item.0.cachemetalvname }} - {% else %} - --poolmetadata {{ item.0.vgname }}/{{ item.0.cachelvname }}_meta - {% endif %} - --poolmetadataspare n - --cachemode {{item.0.cachemode | default('writethrough')}} - "{{item.0.vgname}}/{{item.0.cachelvname}}" - loop: "{{ ((gluster_infra_cache_vars is not none and gluster_infra_cache_vars) or default([])) | zip(((checkpool_attrs is not none and checkpool_attrs.results) or default([]))) | list }}" - when: item.1.stdout.find('C') != 0 + lvconvert -y --type cache-pool --poolmetadata {{ item.cachemetalvname }} + --poolmetadataspare n + --cachemode {{item.cachemode | default('writethrough')}} + "/dev/{{item.vgname}}/{{item.cachelvname}}" + with_items: "{{ gluster_infra_cache_vars }}" + when: item.cachemetalvname is defined + +# It is valid not to have cachemetalvname! Writing a separate task not to +# complicate things. +- name: Convert logical volume to a cache pool LV without cachemetalvname + command: > + lvconvert -y --type cache-pool + --poolmetadataspare n + --cachemode {{item.cachemode | default('writethrough')}} + "/dev/{{item.vgname}}/{{item.cachelvname}}" + with_items: "{{ gluster_infra_cache_vars }}" + when: item.cachemetalvname is not defined # Run lvs -a -o +devices to see the cache settings - name: Convert an existing logical volume to a cache LV command: > - lvconvert -y --type cache --cachepool {{ item.0.vgname }}/{{ item.0.cachelvname }} - {{ item.0.vgname }}/{{ item.0.cachetarget | default(item.0.cachethinpoolname) }} - loop: "{{ ((gluster_infra_cache_vars is not none and gluster_infra_cache_vars) or default([])) | zip(((datapoolcache_attrs is not none and datapoolcache_attrs.results) or default([]))) | list }}" - loop_control: - index_var: index - #check if the LV exists and is not yet converted to a cache volume - when: datapool_attrs.results[index].stdout is defined and datapool_attrs.results[index].stdout|length>0 and item.1.stdout.find(item.0.cachelvname) == -1 - + lvconvert -y --type cache --cachepool "/dev/{{item.vgname}}/{{item.cachelvname}}" + "/dev/{{item.vgname}}/{{item.cachethinpoolname}}" + with_items: "{{ gluster_infra_cache_vars }}" diff --git a/roles/backend_setup/tasks/thin_pool_create.yml b/roles/backend_setup/tasks/thin_pool_create.yml index 4c40b00..ad7cc88 100644 --- a/roles/backend_setup/tasks/thin_pool_create.yml +++ b/roles/backend_setup/tasks/thin_pool_create.yml @@ -42,34 +42,34 @@ set_fact: gluster_phase2_has_missing_devices: true loop: "{{ lvtp_device_exists.results }}" - when: item.stdout_lines is defined and "0" in item.stdout_lines + when: item.stdout_lines is defined and "0" in item.stdout_lines - name: Check if thinpool exists - shell: "lvs --options 'lv_attr' -a --noheadings {{item.vgname}}/{{item.thinpoolname}}| sed 's/^ *//;s/$//'" + shell: "lvs --options 'lv_attr' -a --noheadings {{item.vgname}}/{{item.thinpoolname}}| sed 's/^ *//;s/$//'" register: thinpool_attrs with_items: "{{ gluster_infra_thinpools }}" loop_control: index_var: index - when: > - gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 + when: > + gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined and lvtp_device_exists.results[index].stdout_lines is defined and "0" not in lvtp_device_exists.results[index].stdout_lines and ((item.opts is defined and "raid" in item.opts) or item.meta_pvs is defined or item.meta_opts is defined) - include_tasks: get_vg_groupings.yml - vars: + vars: volume_groups: >- {%- set output=[] -%} {%- for cnf in gluster_infra_thinpools -%} {%- if cnf is defined and cnf is not none and cnf.thinpoolname is defined and cnf.vgname is defined - and (thinpool_attrs.results[loop.index0].stdout is not defined or thinpool_attrs.results[loop.index0].stdout.find("t") != 0) + and (thinpool_attrs.results[loop.index0].stdout is not defined or thinpool_attrs.results[loop.index0].stdout.find("t") != 0) and (cnf.meta_pvs is defined or cnf.pvs is defined) -%} {{- output.append({"vgname": cnf.vgname, "pvname": (cnf.pvs|default('') ~ ',' ~ (cnf.meta_pvs|default(''))).split(',') | select | list | unique | join(',')}) -}} {%- endif -%} {%- endfor -%} {{- output | to_json -}} - when: gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 + when: gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 # https://github.com/ansible/ansible/issues/13262 # block of tasks, which is executed when there are valid pools and pool items are configured. @@ -82,25 +82,25 @@ vg: "{{ (item.value | first).vgname }}" pvs: "{{ item.value | json_query('[].pvname') | unique | join(',') }}" pv_options: >- - {% if (item.value | first).raid is defined and (item.value | first).raid is not none - and (item.value | first).raid.level is defined and (item.value | first).raid.devices is defined and (item.value | first).raid.stripe is defined + {% if (item.value | first).raid is defined and (item.value | first).raid is not none + and (item.value | first).raid.level is defined and (item.value | first).raid.devices is defined and (item.value | first).raid.stripe is defined and (item.value | first).raid.level in [0,5,6,10]%} {% if (item.value | first).raid.level == 0 %} - {{ "--dataalignment " ~ ((item.value | first).raid.devices|int * (item.value | first).raid.stripe|int)|int ~ "K"}} + {{ "--dataalignment " ~ ((item.value | first).raid.devices|int * (item.value | first).raid.stripe|int)|int ~ "K"}} {% elif (item.value | first).raid.level == 5 %} - {{ "--dataalignment " ~ (((item.value | first).raid.devices|int-1) * (item.value | first).raid.stripe|int)|int ~ "K"}} + {{ "--dataalignment " ~ (((item.value | first).raid.devices|int-1) * (item.value | first).raid.stripe|int)|int ~ "K"}} {% elif (item.value | first).raid.level == 6 %} - {{ "--dataalignment " ~ (((item.value | first).raid.devices|int-2) * (item.value | first).raid.stripe|int)|int ~ "K"}} + {{ "--dataalignment " ~ (((item.value | first).raid.devices|int-2) * (item.value | first).raid.stripe|int)|int ~ "K"}} {% elif (item.value | first).raid.level == 10 %} - {{ "--dataalignment " ~ (((item.value | first).raid.devices|int/2) * (item.value | first).raid.stripe|int)|int ~ "K"}} - {% endif %} + {{ "--dataalignment " ~ (((item.value | first).raid.devices|int/2) * (item.value | first).raid.stripe|int)|int ~ "K"}} + {% endif %} {% else %} {{ "--dataalignment 256K" }} {% endif %} - + pesize: >- - {%- if (item.value | first).raid is defined and (item.value | first).raid is not none - and (item.value | first).raid.level is defined and (item.value | first).raid.devices is defined and (item.value | first).raid.stripe is defined + {%- if (item.value | first).raid is defined and (item.value | first).raid is not none + and (item.value | first).raid.level is defined and (item.value | first).raid.devices is defined and (item.value | first).raid.stripe is defined and (item.value | first).raid.level in [0,5,6,10] -%} {%- if (item.value | first).raid.level == 0 -%} {{- ((item.value | first).raid.devices|int * (item.value | first).raid.stripe|int)|int ~ "K"-}} @@ -117,14 +117,14 @@ loop: "{{ gluster_volumes_by_groupname | dict2items }}" loop_control: index_var: index - when: > - gluster_volumes_by_groupname is defined and gluster_volumes_by_groupname is not none and gluster_volumes_by_groupname|length >0 + when: > + gluster_volumes_by_groupname is defined and gluster_volumes_by_groupname is not none and gluster_volumes_by_groupname|length >0 and item.value|length>0 - name: update LVM fact's - setup: + setup: filter: 'ansible_lvm' - when: gluster_changed_vgs.changed + when: gluster_changed_vgs.changed - name: Create a LV thinpool-data lvol: @@ -132,16 +132,16 @@ shrink: false vg: "{{ item.vgname }}" lv: "{{ item.thinpoolname }}" - pvs: "{{ item.pvs | default() }}" + pvs: "{{ item.pvs | default() }}" size: "{{ item.thinpoolsize | default('100%FREE') }}" - opts: " + opts: " {{ item.opts | default('') }} " with_items: "{{ gluster_infra_thinpools }}" loop_control: index_var: index - when: > - gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 - and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined + when: > + gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 + and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined and lvtp_device_exists.results[index].stdout_lines is defined and "0" not in lvtp_device_exists.results[index].stdout_lines and (thinpool_attrs.results[index].stdout is not defined or thinpool_attrs.results[index].stdout.find("t") != 0) and ((item.opts is defined and "raid" in item.opts) or item.meta_pvs is defined or item.meta_opts is defined) @@ -153,16 +153,16 @@ shrink: false vg: "{{ item.vgname }}" lv: "{{ item.thinpoolname }}_meta" - pvs: "{{ ((item.meta_pvs is defined and item.meta_pvs) or item.pvs) | default() }}" + pvs: "{{ ((item.meta_pvs is defined and item.meta_pvs) or item.pvs) | default() }}" size: "{{ item.poolmetadatasize | default('16G') }}" - opts: " + opts: " {{ ((item.meta_opts is defined and item.meta_opts) or item.opts) | default('') }} " with_items: "{{ gluster_infra_thinpools }}" loop_control: index_var: index - when: > - gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 - and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined + when: > + gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 + and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined and lvtp_device_exists.results[index].stdout_lines is defined and "0" not in lvtp_device_exists.results[index].stdout_lines and (thinpool_attrs.results[index].stdout is not defined or thinpool_attrs.results[index].stdout.find("t") != 0) and ((item.opts is defined and "raid" in item.opts) or item.meta_pvs is defined or item.meta_opts is defined) @@ -173,28 +173,28 @@ shell: >- lvconvert -y --type thin-pool {{item.vgname}}/{{item.thinpoolname}} --poolmetadata {{ item.thinpoolname }}_meta - {% if item.raid is defined and item.raid is not none - and item.raid.level is defined and item.raid.devices is defined and item.raid.stripe is defined + {% if item.raid is defined and item.raid is not none + and item.raid.level is defined and item.raid.devices is defined and item.raid.stripe is defined and item.raid.level in [0,5,6,10]%} {% if item.raid.level == 0 %} - {{ "--chunksize " ~ (item.raid.devices|int * item.raid.stripe|int)|int ~ "K"}} + {{ "--chunksize " ~ (item.raid.devices|int * item.raid.stripe|int)|int ~ "K"}} {% elif item.raid.level == 5 %} - {{ "--chunksize " ~ ((item.raid.devices|int-1) * item.raid.stripe|int)|int ~ "K"}} + {{ "--chunksize " ~ ((item.raid.devices|int-1) * item.raid.stripe|int)|int ~ "K"}} {% elif item.raid.level == 6 %} - {{ "--chunksize " ~ ((item.raid.devices|int-2) * item.raid.stripe|int)|int ~ "K"}} + {{ "--chunksize " ~ ((item.raid.devices|int-2) * item.raid.stripe|int)|int ~ "K"}} {% elif item.raid.level == 10 %} - {{ "--chunksize " ~ ((item.raid.devices|int/2) * item.raid.stripe|int)|int ~ "K"}} - {% endif %} + {{ "--chunksize " ~ ((item.raid.devices|int/2) * item.raid.stripe|int)|int ~ "K"}} + {% endif %} {% else %} {{ "--chunksize 256K" }} - {% endif %} + {% endif %} --zero n with_items: "{{ gluster_infra_thinpools }}" loop_control: index_var: index - when: > - gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 - and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined + when: > + gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 + and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined and lvtp_device_exists.results[index].stdout_lines is defined and "0" not in lvtp_device_exists.results[index].stdout_lines and (thinpool_attrs.results[index].stdout is not defined or thinpool_attrs.results[index].stdout.find("t") != 0) and ((item.opts is defined and "raid" in item.opts) or item.meta_pvs is defined or item.meta_opts is defined) @@ -208,32 +208,43 @@ pvs: "{{ item.pvs | default() }}" thinpool: "{{ item.thinpoolname }}" size: "{{ item.thinpoolsize | default('100%FREE') }}" - opts: >- - {% if item.raid is defined and item.raid is not none - and item.raid.level is defined and item.raid.devices is defined and item.raid.stripe is defined + opts: >- + {% if item.raid is defined and item.raid is not none + and item.raid.level is defined and item.raid.devices is defined and item.raid.stripe is defined and item.raid.level in [0,5,6,10]%} {% if item.raid.level == 0 %} - {{ "--chunksize " ~ (item.raid.devices|int * item.raid.stripe|int)|int ~ "K"}} + {{ "--chunksize " ~ (item.raid.devices|int * item.raid.stripe|int)|int ~ "K"}} {% elif item.raid.level == 5 %} - {{ "--chunksize " ~ ((item.raid.devices|int-1) * item.raid.stripe|int)|int ~ "K"}} + {{ "--chunksize " ~ ((item.raid.devices|int-1) * item.raid.stripe|int)|int ~ "K"}} {% elif item.raid.level == 6 %} - {{ "--chunksize " ~ ((item.raid.devices|int-2) * item.raid.stripe|int)|int ~ "K"}} + {{ "--chunksize " ~ ((item.raid.devices|int-2) * item.raid.stripe|int)|int ~ "K"}} {% elif item.raid.level == 10 %} - {{ "--chunksize " ~ ((item.raid.devices|int/2) * item.raid.stripe|int)|int ~ "K"}} - {% endif %} + {{ "--chunksize " ~ ((item.raid.devices|int/2) * item.raid.stripe|int)|int ~ "K"}} + {% endif %} {% else %} {{ "--chunksize 256K" }} - {% endif %} + {% endif %} --poolmetadatasize {{ item.poolmetadatasize }} --zero n {{ item.opts | default('') }} with_items: "{{ gluster_infra_thinpools }}" loop_control: index_var: index - when: > - gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 - and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined - and lvtp_device_exists.results[index].stdout_lines is defined and "0" not in lvtp_device_exists.results[index].stdout_lines - and ((item.opts is not defined or "raid" not in item.opts) and item.meta_pvs is not defined and item.meta_opts is not defined) + when: > + gluster_infra_thinpools is defined and gluster_infra_thinpools is not none and gluster_infra_thinpools|length >0 + and item is defined and item is not none and item.thinpoolname is defined and item.thinpoolname is defined and item.vgname is defined + and item.raid is defined #end-block - + +- name: Create a LV thinpool for similar device types + lvol: + state: present + shrink: false + vg: "{{ item.vgname }}" + thinpool: "{{ item.thinpoolname }}" + size: "{{ item.thinpoolsize | default('100%FREE') }}" + opts: " --chunksize {{ lv_chunksize }} + --poolmetadatasize {{ item.poolmetadatasize }} + --zero n" + with_items: "{{ gluster_infra_thinpools }}" + when: gluster_infra_thinpools is defined and item.raid is not defined