50 lines
1.7 KiB
YAML
50 lines
1.7 KiB
YAML
---
|
|
# tasks file for zfs management
|
|
# Based on: https://github.com/mrlesmithjr/ansible-zfs/blob/master/tasks/manage_zfs.yml
|
|
# Expected variables in your inventory: zfs_pools.
|
|
|
|
- name: Checking existing zpool(s)
|
|
ansible.builtin.command: "zpool list -H -o name"
|
|
changed_when: false
|
|
register: current_zp_state
|
|
check_mode: false
|
|
when: zfs_pools is defined
|
|
|
|
- name: Gather zpool status
|
|
ansible.builtin.command: zpool status
|
|
changed_when: false
|
|
register: zpool_devices
|
|
when: zfs_pools is defined
|
|
|
|
- name: Creating basic zpool(s)
|
|
ansible.builtin.command: "zpool create {{ '-o '+ item.options.items() |map('join', '=') | join (' -o ') if item.options is defined else '' }} {{ item.name }} {{
|
|
item.devices|join (' ') }}"
|
|
with_items: "{{ zfs_pools }}"
|
|
when:
|
|
- zfs_pools is defined
|
|
- item.type == "basic"
|
|
- item.name not in current_zp_state.stdout
|
|
- item.state == "present"
|
|
- item.devices[0] not in zpool_devices.stdout
|
|
|
|
- name: Creating mirror/zraid zpool(s)
|
|
ansible.builtin.command: "zpool create {{ '-o '+ item.options.items() |map('join', '=') | join (' -o ') if item.options is defined else '' }} {{ item.name }} {{
|
|
item.type }} {{ item.devices|join (' ') }}"
|
|
with_items: "{{ zfs_pools }}"
|
|
when:
|
|
- zfs_pools is defined
|
|
- item.type != "basic"
|
|
- item.name not in current_zp_state.stdout
|
|
- item.state == "present"
|
|
- item.devices[0] not in zpool_devices.stdout
|
|
|
|
- name: Deleting zpool(s) with care
|
|
ansible.builtin.include_tasks: "./delete-pool.yml"
|
|
when:
|
|
- zfs_pools is defined
|
|
- zpool.name in current_zp_state.stdout_lines
|
|
- zpool.state == "absent"
|
|
loop: "{{ zfs_pools }}"
|
|
loop_control:
|
|
loop_var: zpool
|