48 lines
1.2 KiB
YAML
48 lines
1.2 KiB
YAML
|
---
|
||
|
|
||
|
- name: Check if pool exists
|
||
|
command: zpool list -Ho name {{ pool.name }}
|
||
|
changed_when: false
|
||
|
failed_when: false
|
||
|
check_mode: no
|
||
|
register: pool_exists
|
||
|
|
||
|
- name: Create pool
|
||
|
check_mode: no
|
||
|
command: >-
|
||
|
zpool create
|
||
|
{{ '-n' if ansible_check_mode else '' }}
|
||
|
{{ '-m ' + pool.mountpoint if pool.mountpoint is defined else '' }}
|
||
|
{{ pool.name }}
|
||
|
{% if pool.vdevs is defined %}
|
||
|
{% for vdev in pool.vdevs %}
|
||
|
{{ vdev.type }}
|
||
|
{% for disk in vdev.disks %}
|
||
|
{{ disk }}
|
||
|
{% endfor %}
|
||
|
{% endfor %}
|
||
|
{% if pool.spares is defined %}
|
||
|
spare
|
||
|
{% for disk in pool.spares %}
|
||
|
{{ disk }}
|
||
|
{% endfor %}
|
||
|
{% endif %}
|
||
|
{% else %}
|
||
|
{% for disk in pool.disks %}
|
||
|
{{ disk }}
|
||
|
{% endfor %}
|
||
|
{% endif %}
|
||
|
{% if pool.properties is defined %}
|
||
|
{% for property in pool.properties | dict2items %}
|
||
|
-o {{ property.key }}={{ property.value }}
|
||
|
{% endfor %}
|
||
|
{% endif %}
|
||
|
when: pool_exists.rc == 1
|
||
|
|
||
|
- name: Create datasets in the pool
|
||
|
community.general.zfs:
|
||
|
name: "{{ pool.name }}/{{ item.name }}"
|
||
|
extra_zfs_properties: "{{ item.properties | default(omit) }}"
|
||
|
state: present
|
||
|
loop: "{{ pool.datasets | default(omit) }}"
|