added role for proxmox and zfs
This commit is contained in:
parent
f44ee01827
commit
14a6a2ab3f
7 changed files with 147 additions and 0 deletions
7
books/hypervisor.yml
Executable file
7
books/hypervisor.yml
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env ansible-playbook
|
||||
---
|
||||
|
||||
- hosts: proxmox
|
||||
roles:
|
||||
# - proxmox
|
||||
- zfs
|
|
@ -24,3 +24,23 @@ interfaces:
|
|||
|
||||
ipv4_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
|
||||
|
||||
|
|
6
roles/proxmox/handlers/main.yml
Normal file
6
roles/proxmox/handlers/main.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
|
||||
- name: Restart pveproxy
|
||||
systemd:
|
||||
name: pveproxy
|
||||
state: restarted
|
19
roles/proxmox/tasks/main.yml
Normal file
19
roles/proxmox/tasks/main.yml
Normal 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
|
||||
|
40
roles/zfs/examples/vars.yml
Normal file
40
roles/zfs/examples/vars.yml
Normal 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
|
||||
|
47
roles/zfs/tasks/create_pool.yml
Normal file
47
roles/zfs/tasks/create_pool.yml
Normal 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
8
roles/zfs/tasks/main.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
|
||||
- name: Create ZFS pools
|
||||
include_tasks: create_pool.yml
|
||||
loop: "{{ zfs_pools }}"
|
||||
loop_control:
|
||||
loop_var: pool
|
||||
|
Loading…
Reference in a new issue