From e03c04873ce388114bf9f1f6236baed3b0e465eb Mon Sep 17 00:00:00 2001 From: Crest Date: Mon, 14 Sep 2020 01:25:20 +0200 Subject: [PATCH] Create (multiple) ZFS volumes per guest --- roles/bhyve-storage/tasks/main.yml | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 roles/bhyve-storage/tasks/main.yml diff --git a/roles/bhyve-storage/tasks/main.yml b/roles/bhyve-storage/tasks/main.yml new file mode 100644 index 0000000..8287358 --- /dev/null +++ b/roles/bhyve-storage/tasks/main.yml @@ -0,0 +1,42 @@ +--- +- name: Create common bhyve datasets + zfs: + name: '{{ bhyve_pool }}/{{ item.name }}' + state: present + extra_zfs_properties: '{{ item.properties | default(omit) }}' + loop_control: + label: '{{ item.name }}' + with_items: + - name: bhyve + properties: + mountpoint: /bhyve + - name: bhyve/images + - name: bhyve/guests + properties: + volmode: dev + +- name: Create bhyve guest datasets + zfs: + name: '{{ bhyve_pool }}/guests/{{ item.name }}' + state: present + loop_control: + label: '{{ item.name }}' + with_items: '{{ bhyve_guests }}' + +- name: Gather facts over existing datasets + zfs_facts: + name: '{{ bhyve_pool }}/bhyve/guests' + recurse: yes + type: volume + +- name: Create bhyve guest ZFS volumes + zfs: + name: '{{ bhyve_pool}}/bhyve/guests/{{ item.0.name }}/{{ item.1.name }}' + state: present + extra_zfs_properties: '{{ item.1.properties }}' + when: 'ansible_zfs_datasets | selectattr("name", "equalto", [bhyve_pool, "bhyve/guests", item.0.name, item.1.name] | join("/") ) | list | length < 1' + loop_control: + label: '{{ item.0.name }} : {{ item.1.name }}' + with_subelements: + - '{{ bhyve_guests }}' + - disks