diff options
author | Christian Pointner <equinox@spreadspace.org> | 2024-01-10 15:53:25 +0100 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2024-01-10 16:05:57 +0100 |
commit | edd1d3174982c5f4d5253944369002e9343cd5e4 (patch) | |
tree | 6d299b34da46fa696eecd93fd72eb7acf9c53456 /roles/storage/lvm | |
parent | cleanup testvm config (diff) |
storage/lvm/base: allow global volumes
Diffstat (limited to 'roles/storage/lvm')
-rw-r--r-- | roles/storage/lvm/base/defaults/main.yml | 27 | ||||
-rw-r--r-- | roles/storage/lvm/base/filter_plugins/lvm.py | 31 | ||||
-rw-r--r-- | roles/storage/lvm/base/tasks/main.yml | 11 | ||||
-rw-r--r-- | roles/storage/lvm/volume/defaults/main.yml | 2 | ||||
-rw-r--r-- | roles/storage/lvm/volume/tasks/main.yml | 1 |
5 files changed, 69 insertions, 3 deletions
diff --git a/roles/storage/lvm/base/defaults/main.yml b/roles/storage/lvm/base/defaults/main.yml index 74dc0c20..36df4a51 100644 --- a/roles/storage/lvm/base/defaults/main.yml +++ b/roles/storage/lvm/base/defaults/main.yml @@ -6,3 +6,30 @@ lvm_groups: {} # pvs: # - /dev/sdb # - /dev/sdc1 + +lvm_volumes: {} + +# lvm_volumes: +# system/test: +# vg: "{{ host_name }}" +# lv: test +# size: 1G +# fs: ext4 +# dest: /srv/test +# foo/test: &_lvm_thinpool_foo_test_ +# vg: foo +# lv: test +# thinpool: true +# size: 4G +# foo/blub: +# parent: *_lvm_thinpool_foo_test_ +# lv: blub +# size: 3G +# fs: ext4 +# dest: /srv/blub +# foo/hugo: +# parent: *_lvm_thinpool_foo_test_ +# lv: hugo +# size: 2G +# fs: ext4 +# dest: /srv/hugo diff --git a/roles/storage/lvm/base/filter_plugins/lvm.py b/roles/storage/lvm/base/filter_plugins/lvm.py new file mode 100644 index 00000000..0f8b1e97 --- /dev/null +++ b/roles/storage/lvm/base/filter_plugins/lvm.py @@ -0,0 +1,31 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from functools import partial + +from ansible import errors + + +def lvm_volume_list(data): + try: + thinpools = [] + volumes = [] + for name, volume in data.items(): + entry = {'name': name, 'volume': volume} + if 'thinpool' in volume and volume['thinpool'] == True: + thinpools.append(entry) + else: + volumes.append(entry) + return thinpools + volumes + except Exception as e: + raise errors.AnsibleFilterError("lvm_volume_list(): %s" % str(e)) + + +class FilterModule(object): + + filter_map = { + 'lvm_volume_list': lvm_volume_list, + } + + def filters(self): + return self.filter_map diff --git a/roles/storage/lvm/base/tasks/main.yml b/roles/storage/lvm/base/tasks/main.yml index ddcd49c7..75af733b 100644 --- a/roles/storage/lvm/base/tasks/main.yml +++ b/roles/storage/lvm/base/tasks/main.yml @@ -1,5 +1,5 @@ --- -- name: create volume groups +- name: create lvm volume groups loop: "{{ lvm_groups | dict2items }}" loop_control: label: "{{ item.key }}" @@ -10,3 +10,12 @@ pesize: "{{ item.value.pesize | default(omit) }}" pv_options: "{{ item.value.pv_options | default(omit) }}" state: present + +- name: create lvm volumes + loop: "{{ lvm_volumes | lvm_volume_list }}" + loop_control: + label: "{{ item.name }}" + vars: + lvm_volume: "{{ item.volume }}" + include_role: + name: storage/lvm/volume diff --git a/roles/storage/lvm/volume/defaults/main.yml b/roles/storage/lvm/volume/defaults/main.yml index a64a7c86..6c0d6cf5 100644 --- a/roles/storage/lvm/volume/defaults/main.yml +++ b/roles/storage/lvm/volume/defaults/main.yml @@ -1,7 +1,7 @@ --- # lvm_volume: # parent: -# type: lvm +# thinpool: true # ... # vg: foo # lv: bar diff --git a/roles/storage/lvm/volume/tasks/main.yml b/roles/storage/lvm/volume/tasks/main.yml index 166d6ff8..5b9cb1e7 100644 --- a/roles/storage/lvm/volume/tasks/main.yml +++ b/roles/storage/lvm/volume/tasks/main.yml @@ -4,7 +4,6 @@ assert: msg: "the volume parent must be a lvm thinpool" that: - - lvm_volume.parent.type == 'lvm' - (lvm_volume.parent.thinpool | default(false)) - name: install thin-provisioning-tools |