bind-mounts per ansible (#213)

Co-authored-by: Michael Grote <michael.grote@posteo.de>
Reviewed-on: mg/ansible#213
Co-authored-by: mg <mg@noreply.git.mgrote.net>
Co-committed-by: mg <mg@noreply.git.mgrote.net>
This commit is contained in:
Michael Grote 2021-10-10 16:47:36 +02:00
parent 71aa41cb24
commit ef585b3639
7 changed files with 128 additions and 16 deletions

View File

@ -1,19 +1,4 @@
---
# Bind Mounts - fileserver
# pct set 127 -mp0 /hdd_data_raidz/videos,mp=/shares_videos
# pct set 127 -mp1 /hdd_data_raidz/data_crypt,mp=/shares_data_crypt
# pct set 127 -mp2 /hdd_data_raidz/pve_backup,mp=/shares_pve_backup
# pct set 127 -mp3 /hdd_data_raidz/papa_backup,mp=/shares_papa_backup
# pct set 127 -mp4 /hdd_data_raidz/music,mp=/shares_music
# pct set 127 -mp5 /hdd_data_raidz/tmp,mp=/shares_tmp
# pct set 127 -mp6 /hdd_data_raidz/archiv,mp=/shares_archiv
# pct set 127 -mp7 /hdd_data_raidz/bilder,mp=/shares_bilder
# pct set 127 -mp8 /hdd_data_raidz/hm,mp=/shares_hm
# pct set 127 -mp9 /hdd_data_raidz/scans,mp=/shares_scans
# pct set 127 -mp10 /hdd_data_raidz/restic,mp=/shares_restic
# pct set 127 -mp11 /hdd_data_raidz/amd,mp=/shares_amd
# pct set 127 -mp12 /hdd_data_raidz/backup,mp=/shares_backup
### mgrote.smb_fileserver
smb_users:
- name: 'annemariedroessler2'

View File

@ -215,7 +215,8 @@
template: '31tage'
- path: hdd_data_raidz/restic
recursive: 'no'
snapshots: false
snapshots: true
template: '3tage'
sanoid_templates:
- name: '31tage'
keep_hourly: '24' # Aufheben (Stunde)
@ -260,3 +261,62 @@
cv4pve_vmid: all,-127,-158,-112,-100
cv4pve_keep_snapshots: 5
cv4pve_dl_link: "https://github.com/Corsinvest/cv4pve-autosnap/releases/download/v1.10.0/cv4pve-autosnap-linux-x64.zip"
### mgrote.proxmox_bind_mounts
pve_bind_mounts:
- vmid: 105
mp_nr: 1
mp_path_host: /rpool/vm/dir/fileserver2_test
mp_path_guest: /share
- vmid: 127
mp_nr: 0
mp_path_host: /hdd_data_raidz/videos
mp_path_guest: /shares_videos
- vmid: 127
mp_nr: 1
mp_path_host: /hdd_data_raidz/data_crypt
mp_path_guest: /shares_data_crypt
- vmid: 127
mp_nr: 2
mp_path_host: /hdd_data_raidz/pve_backup
mp_path_guest: /shares_pve_backup
- vmid: 127
mp_nr: 3
mp_path_host: /hdd_data_raidz/papa_backup
mp_path_guest: /shares_papa_backup
- vmid: 127
mp_nr: 4
mp_path_host: /hdd_data_raidz/music
mp_path_guest: /shares_music
- vmid: 127
mp_nr: 5
mp_path_host: /hdd_data_raidz/tmp
mp_path_guest: /shares_tmp
- vmid: 127
mp_nr: 6
mp_path_host: /hdd_data_raidz/archiv
mp_path_guest: /shares_archiv
- vmid: 127
mp_nr: 7
mp_path_host: /hdd_data_raidz/bilder
mp_path_guest: /shares_bilder
- vmid: 127
mp_nr: 8
mp_path_host: /hdd_data_raidz/hm
mp_path_guest: /shares_hm
- vmid: 127
mp_nr: 9
mp_path_host: /hdd_data_raidz/scans
mp_path_guest: /shares_scans
- vmid: 127
mp_nr: 10
mp_path_host: /hdd_data_raidz/restic
mp_path_guest: /shares_restic
- vmid: 127
mp_nr: 11
mp_path_host: /hdd_data_raidz/amd
mp_path_guest: /shares_amd
- vmid: 127
mp_nr: 12
mp_path_host: /hdd_data_raidz/backup
mp_path_guest: /shares_backup

View File

@ -20,3 +20,5 @@
when: "'pve2.grote.lan' in inventory_hostname" }
- { role: mgrote.r8152_kernel_module,
tags: "r8152" }
- { role: mgrote.proxmox_bind_mounts,
tags: "bindmounts" }

View File

@ -0,0 +1,16 @@
## mgrote.proxmox_bind_mounts
### Beschreibung
Adds [bind-mounts](https://pve.proxmox.com/wiki/Linux_Container#pct_container_storage) for LXC-Container on Proxmox.
### tested on
- [x] ProxMox 7.*
### Variablen + Defaults
```
pve_bind_mounts: # Dictionary
- vmid: 105 # VMID for which the bind-mount should get created
mp_nr: 1 # Number of the mountpoint
mp_path_host: /rpool/test # Path on the Host
mp_path_guest: /klauspeter # Path in the Guest
```

View File

@ -0,0 +1,13 @@
---
- name: restart lxc
become: true
command: "pct reboot {{ item.vmid }}"
when:
- "reboot_{{item.vmid}} is defined"
- "reboot_{{item.vmid}} is true"
failed_when: false
loop: "{{ pve_bind_mounts }}"
# rebote den lxc wenn:
# - sein variable auf true gesetzt ist
# wird bei mehreren moiunts mehrfach pro host aufgerufen
# aber nur einmal ausgeführt

View File

@ -0,0 +1,29 @@
---
- name: read config
become: true
shell: "pct config {{ item.vmid }} | grep \"mp{{ item.mp_nr }}: {{ item.mp_path_host }},mp={{ item.mp_path_guest }}\""
register: config
changed_when: false
failed_when: false
# prüfe ob bind mount schon vorhanden ist
# exit-code wird unten geprüft
# - name: debug config
# ansible.builtin.debug:
# msg: "{{ config }}"
- name: add bind mounts to container
become: true
command: "pct set {{ item.vmid }} -mp{{ item.mp_nr }} {{ item.mp_path_host }},mp={{ item.mp_path_guest }}"
when: not config.rc == 0
register: restart
notify: restart lxc
# füge bind-mount hinzu falls er fehlt, also rc ungleich 0
# pro bind-mount
- name: set reboot var
set_fact:
"reboot_{{ item.vmid }}": true
when: restart.changed
# setze reboot variable fur handler
# z.B. reboot_105: true

View File

@ -0,0 +1,7 @@
---
- name: loop tasks
include_tasks: bm.yml
loop: "{{ pve_bind_mounts }}"
when:
- pve_bind_mounts is defined
# Loope durch jeden bind-mount