added role for proxmox and zfs

This commit is contained in:
g33kex 2022-07-23 01:37:05 +02:00
parent f44ee01827
commit 14a6a2ab3f
7 changed files with 147 additions and 0 deletions

7
books/hypervisor.yml Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env ansible-playbook
---
- hosts: proxmox
roles:
# - proxmox
- zfs

View file

@ -24,3 +24,23 @@ interfaces:
ipv4_forwarding: false ipv4_forwarding: false
ipv6_forwarding: false ipv6_forwarding: false
## Disks
zfs_pools:
- name: tank0
vdevs:
- type: raidz1
disks:
- sda
- sdb
- sdc
- sdd
- sde
properties:
autoreplace: 'on'
datasets:
- name: iso_images
- name: containers
- name: vms

View file

@ -0,0 +1,6 @@
---
- name: Restart pveproxy
systemd:
name: pveproxy
state: restarted

View file

@ -0,0 +1,19 @@
---
- name: Remove entreprise proxmox repository
apt_repository:
repo: "deb https://enterprise.proxmox.com/debian/pve {{ ansible_facts['lsb']['codename'] }} pve-enterprise"
state: absent
- name: Add non subscription proxmox repository
apt_repository:
repo: "deb [arch=amd64] http://download.proxmox.com/debian/pve {{ ansible_facts['lsb']['codename'] }} pve-no-subscription"
filename: pve-no-subscription
state: present
- name: Remove No Subscription Message
replace:
path: /usr/share/perl5/PVE/API2/Subscription.pm
regexp: 'NotFound'
replace: 'Active'
notify: Restart pveproxy

View file

@ -0,0 +1,40 @@
---
zfs_pools:
- name: prod_pool
mountpoint: none
vdevs:
- type: raidz1
disks:
- ada0
- ada1
- ada2
- type: mirror
disks:
- ada3
- ada4
- type: mirror
disks:
- ada5
- ada6
spares:
- ada7
- ada8
properties:
autoreplace: on
datasets:
- name: dataset0
properties:
quota: '1T'
mountpoint: '/mnt'
- name: non_redondant_pool
disks:
- ada9
- ada10
datasets:
- name: dataset1
properties:
quota: '50G'
- name: dataset2
- name: dataset3

View file

@ -0,0 +1,47 @@
---
- 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) }}"

8
roles/zfs/tasks/main.yml Normal file
View file

@ -0,0 +1,8 @@
---
- name: Create ZFS pools
include_tasks: create_pool.yml
loop: "{{ zfs_pools }}"
loop_control:
loop_var: pool