]> git.apps.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
testnode: Add support to quickly create LVs 362/head
authorDavid Galloway <dgallowa@redhat.com>
Wed, 6 Dec 2017 22:20:27 +0000 (17:20 -0500)
committerDavid Galloway <dgallowa@redhat.com>
Wed, 6 Dec 2017 22:39:18 +0000 (17:39 -0500)
Fixes: http://tracker.ceph.com/issues/22328
Signed-off-by: David Galloway <dgallowa@redhat.com>
roles/testnode/README.rst
roles/testnode/tasks/configure_lvm.yml
roles/testnode/tasks/lvm.yml

index 010696b538051866979accd217f5d3df8ade665b..5d4b92a12b9a8b43e3b6773ea43791a08543c917 100644 (file)
@@ -210,6 +210,16 @@ A dictionary of logical volumes you want created.  See Ansible's docs_ on availa
         vg: vg_hdd
         size: "100%VG"
 
+Setting ``quick_lvs_to_create`` will:
+
+    #. Create one large volume group using all non-root devices listed in ``ansible_devices``
+    #. Create X number of logical volumes equal in size
+
+    Defining this variable will override ``volume_groups`` and ``logical_volumes`` dicts if defined in secrets::
+
+        # Example would create 4 logical volumes each using 25% of a volume group created using all non-root physical volumes
+        quick_lvs_to_create: 4
+
 Tags
 ++++
 
index ccc6aa7438036b8e60b184739882f23fb470cb56..e61719d180e3b8072ea423a655f901bbf40c47b2 100644 (file)
@@ -1,4 +1,58 @@
 ---
+- name: Set root disk
+  set_fact:
+    root_disk: "{{ item.device|regex_replace('[0-9]+', '')|regex_replace('/dev/', '') }}"
+  with_items: "{{ ansible_mounts }}"
+  when:
+    - item.mount == '/'
+    - quick_lvs_to_create is defined
+
+- name: Combine list of non-root disks
+  set_fact:
+      disks_for_vg: "{{ ansible_devices.keys() | sort | reject('match',root_disk) | reject('match','loop') | reject('match','ram') | map('regex_replace','^','/dev/') | join(',') }}"
+  when: quick_lvs_to_create is defined
+
+- set_fact: vg_name=vg_hdd
+  when:
+    - disks_for_vg is defined
+    - "'nvme' not in disks_for_vg"
+
+- set_fact: vg_name=vg_nvme
+  when:
+    - disks_for_vg is defined
+    - "'nvme' in disks_for_vg"
+
+- name: Create volume_groups dict
+  set_fact:
+    volume_groups:
+      "{'{{ vg_name }}': {'pvs': '{{ disks_for_vg }}' }}"
+  when: vg_name is defined
+
+# This isn't perfect but with the |int at the end, this'll just round down
+# if quick_lvs_to_create won't divide evenly to make sure the VG doesn't run out of space
+- name: Determine desired logical volume percentage size
+  set_fact:
+    quick_lv_size: "{{ (100 / quick_lvs_to_create|int)|int }}"
+  when: quick_lvs_to_create is defined
+
+- name: Create logical_volumes dict
+  set_fact:
+    logical_volumes:
+      "{
+         {%- for lv in range(quick_lvs_to_create|int) -%}
+         'lv_{{ lv + 1 }}':
+           {
+             'vg': '{{ vg_name }}',
+             'size': '{{ quick_lv_size }}%VG',
+             'scratch_dev': true
+           }
+           {%- if not loop.last -%}
+             ,
+           {%- endif -%}
+         {%- endfor -%}
+       }"
+  when: quick_lvs_to_create is defined
+
 - name: "Create volume group(s)"
   lvg:
     vg: "{{ item.key }}"
index a6e9c105fb4640691b30bd9b8e076fa9629dea05..6847ed486c2e59bc49748d927f000b946ee9d206 100644 (file)
@@ -9,4 +9,5 @@
 
 - include: configure_lvm.yml
   when: (logical_volumes is defined) or
-        (volume_groups is defined)
+        (volume_groups is defined) or
+        (quick_lvs_to_create is defined)