Initialer Import der Synology Scripts
This commit is contained in:
Executable
+100
@@ -0,0 +1,100 @@
|
||||
---
|
||||
- name: HEIMLAN NFS Mount stabil und robust
|
||||
hosts: all
|
||||
become: true
|
||||
gather_facts: true
|
||||
|
||||
vars:
|
||||
mount_path: /mnt/HEIMLAN
|
||||
nfs_export: "/volume1/HEIMLAN"
|
||||
|
||||
tasks:
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 1. NFS Client Installation
|
||||
# ------------------------------------------------------------
|
||||
|
||||
- name: Debian/Ubuntu NFS Client installieren
|
||||
apt:
|
||||
name: nfs-common
|
||||
state: present
|
||||
update_cache: true
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
- name: RedHat NFS Client installieren
|
||||
yum:
|
||||
name: nfs-utils
|
||||
state: present
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 2. NFS Server Mapping (robust, kein Fail bei unbekannten Netzen)
|
||||
# ------------------------------------------------------------
|
||||
|
||||
- name: NFS Server bestimmen
|
||||
set_fact:
|
||||
nfs_server: >-
|
||||
{% if ansible_default_ipv4.address.startswith('9.99') %}
|
||||
9.99.50.20
|
||||
{% else %}
|
||||
192.168.1.230
|
||||
{% endif %}
|
||||
|
||||
- name: Debug Mapping
|
||||
debug:
|
||||
msg: "Host {{ ansible_default_ipv4.address }} -> NFS Server {{ nfs_server }}"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 3. Mountpoint sicherstellen
|
||||
# ------------------------------------------------------------
|
||||
|
||||
- name: Mountpoint erstellen
|
||||
file:
|
||||
path: "{{ mount_path }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 4. Alte kaputte HEIMLAN Einträge entfernen
|
||||
# ------------------------------------------------------------
|
||||
|
||||
- name: Alte HEIMLAN fstab Einträge entfernen
|
||||
lineinfile:
|
||||
path: /etc/fstab
|
||||
state: absent
|
||||
regexp: 'HEIMLAN'
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 5. Korrekten fstab Eintrag schreiben (kein Whitespace Fehler)
|
||||
# ------------------------------------------------------------
|
||||
|
||||
- name: fstab Eintrag setzen (sauber)
|
||||
lineinfile:
|
||||
path: /etc/fstab
|
||||
state: present
|
||||
create: true
|
||||
insertafter: EOF
|
||||
line: "{{ nfs_server | trim }}:{{ nfs_export | trim }} {{ mount_path }} nfs rw,hard,intr,noatime,_netdev,vers=4 0 0"
|
||||
regexp: '^{{ nfs_server | trim | regex_escape() }}:{{ nfs_export | trim | regex_escape() }}'
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 6. Mount ausführen
|
||||
# ------------------------------------------------------------
|
||||
|
||||
- name: Mount aktivieren
|
||||
mount:
|
||||
path: "{{ mount_path }}"
|
||||
state: mounted
|
||||
register: mount_result
|
||||
failed_when: false
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# 7. Ergebnis
|
||||
# ------------------------------------------------------------
|
||||
|
||||
- name: Status anzeigen
|
||||
debug:
|
||||
msg:
|
||||
- "Server: {{ nfs_server }}"
|
||||
- "Mount Path: {{ mount_path }}"
|
||||
- "Mount changed: {{ mount_result.changed | default(false) }}"
|
||||
Reference in New Issue
Block a user