59 lines
1.6 KiB
YAML
Executable File
59 lines
1.6 KiB
YAML
Executable File
---
|
|
- name: SMB Freigabe einrichten und mounten
|
|
hosts: all
|
|
become: true
|
|
gather_facts: true
|
|
|
|
vars:
|
|
mount_point: "/mnt/smbshare"
|
|
smb_server: "//192.168.1.10/DATA"
|
|
credentials_file: "/root/.smbcredentials"
|
|
|
|
tasks:
|
|
|
|
- name: Stelle sicher, dass cifs-utils installiert ist
|
|
ansible.builtin.package:
|
|
name: cifs-utils
|
|
state: present
|
|
|
|
- name: Mountpoint erstellen
|
|
ansible.builtin.file:
|
|
path: "{{ mount_point }}"
|
|
state: directory
|
|
mode: "0755"
|
|
|
|
- name: SMB Credentials Datei erzeugen
|
|
ansible.builtin.copy:
|
|
dest: "{{ credentials_file }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0600"
|
|
content: |
|
|
username={{ smb_user }}
|
|
password={{ smb_pass }}
|
|
|
|
- name: Fstab-Eintrag sicherstellen
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/fstab
|
|
line: "{{ smb_server }} {{ mount_point }} cifs credentials={{ credentials_file }},iocharset=utf8,vers=3.0 0 0"
|
|
state: present
|
|
insertafter: EOF
|
|
backup: yes
|
|
|
|
- name: SMB Freigabe mounten
|
|
ansible.builtin.mount:
|
|
path: "{{ mount_point }}"
|
|
src: "{{ smb_server }}"
|
|
fstype: cifs
|
|
opts: "credentials={{ credentials_file }},iocharset=utf8,vers=3.0"
|
|
state: mounted
|
|
|
|
- name: Prüfen ob SMB Freigabe gemounted wurde
|
|
ansible.builtin.command: mountpoint -q {{ mount_point }}
|
|
register: mount_check
|
|
changed_when: false
|
|
failed_when: mount_check.rc != 0
|
|
|
|
- name: Erfolgsmeldung
|
|
ansible.builtin.debug:
|
|
msg: "SMB Freigabe erfolgreich gemounted auf {{ mount_point }}" |