186 lines
5.2 KiB
YAML
186 lines
5.2 KiB
YAML
---
|
|
|
|
# ---
|
|
# Samba Server
|
|
# ---
|
|
|
|
- name: (samba-install.yml) Ensure samba packages server (buster) are installed.
|
|
package:
|
|
pkg: '{{ apt_install_server_samba }}'
|
|
state: present
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
tags:
|
|
- samba-server
|
|
|
|
- name: (samba-install.yml) Ensure samba share directories exists
|
|
file:
|
|
path: "{{ item.path }}"
|
|
owner: "root"
|
|
group: "{{ item.group_write_list }}"
|
|
mode: '2770'
|
|
state: directory
|
|
with_items: "{{ samba_shares }}"
|
|
loop_control:
|
|
label: '{{ item.name }}'
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
tags:
|
|
- samba-shares
|
|
|
|
|
|
# ---
|
|
# /etc/samba/smb.conf
|
|
# ---
|
|
|
|
- name: (samba-install.yml) Check if file '/etc/samba/smb.conf.ORIG exists'
|
|
stat:
|
|
path: /etc/samba/smb.conf.ORIG
|
|
register: smb_conf_exists
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
tags:
|
|
- samba-server
|
|
|
|
- name: (samba-install.yml) Backup existing file /etc/samba/smb.conf
|
|
command: cp -a /etc/samba/smb.conf /etc/samba/smb.conf.ORIG
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
- smb_conf_exists.stat.exists == False
|
|
tags:
|
|
- samba-server
|
|
|
|
|
|
- name: (samba-install.yml) /etc/samba/smb.conf
|
|
template:
|
|
dest: /etc/samba/smb.conf
|
|
src: etc/samba/smb.conf.j2
|
|
owner: root
|
|
group: root
|
|
mode: 0644
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
notify:
|
|
- Restart smbd
|
|
- Restart nmbd
|
|
tags:
|
|
- samba-server
|
|
|
|
|
|
- name: (samba-install.yml) Ensure file /etc/samba/users.map exists
|
|
copy:
|
|
src: "{{ role_path + '/files/etc/samba/users.map' }}"
|
|
dest: /etc/samba/users.map
|
|
owner: root
|
|
group: root
|
|
mode: 0644
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
notify:
|
|
- Restart smbd
|
|
- Restart nmbd
|
|
tags:
|
|
- samba-server
|
|
|
|
|
|
# ---
|
|
# Cronjob for cleaning up samba trash dirs
|
|
# ---
|
|
|
|
- name: (samba-install.yml) Check if file '/root/bin/samba/clean_samba_trash.sh' exists
|
|
stat:
|
|
path: /root/bin/samba/clean_samba_trash.sh
|
|
register: clean_samba_trash_exists
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
|
|
- name: (samba-install.yml) Adjust configuration for script 'clean_samba_trash.sh'
|
|
template:
|
|
dest: /root/bin/samba/conf/clean_samba_trash.conf
|
|
src: root/bin/samba/conf/clean_samba_trash.conf.j2
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
- clean_samba_trash_exists.stat.exists|bool
|
|
tags:
|
|
- samba-server
|
|
|
|
|
|
- name: (samba-install.yml) Check if cleaning up trash dirs is configured
|
|
lineinfile:
|
|
path: /root/bin/samba/conf/clean_samba_trash.conf
|
|
regexp: "^trash_dirs=*"
|
|
state: absent
|
|
check_mode: yes
|
|
changed_when: false
|
|
register: clean_samba_trash_dirs
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
|
|
|
|
- name: (samba-install.yml) Creates a cron job for cleaning up samba trash dirs
|
|
cron:
|
|
name: '{{ samba_cronjob_trash_dirs.name }}'
|
|
minute: '{{ samba_cronjob_trash_dirs.minute }}'
|
|
hour: "{{ samba_cronjob_trash_dirs.hour | default('*') }}"
|
|
day: "{{ samba_cronjob_trash_dirs.hour.day | default('*') }}"
|
|
month: "{{ samba_cronjob_trash_dirs.hour.month| default('*') }}"
|
|
weekday: "{{ samba_cronjob_trash_dirs.hour.weekday| default('*') }}"
|
|
user: "{{ samba_cronjob_trash_dirs.user | default('root') }}"
|
|
job: "{{ samba_cronjob_trash_dirs.job }}"
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
- clean_samba_trash_dirs.found
|
|
|
|
|
|
# ---
|
|
# Cronjob for setting permissions on samba shares
|
|
# ---
|
|
|
|
- name: (samba-install.yml) Check if file '/root/bin/samba/set_permissions_samba_shares.sh' exists
|
|
stat:
|
|
path: /root/bin/samba/set_permissions_samba_shares.sh
|
|
register: set_permissions_on_samba_shares_exists
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
|
|
- name: (samba-install.yml) Adjust configuration for script 'set_permissions_samba_shares.sh'
|
|
template:
|
|
dest: /root/bin/samba/conf/set_permissions_samba_shares.conf
|
|
src: root/bin/samba/conf/set_permissions_samba_shares.conf.j2
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
- set_permissions_on_samba_shares_exists.stat.exists|bool
|
|
tags:
|
|
- samba-server
|
|
|
|
|
|
- name: (samba-install.yml) Creates a cron job for cleaning up samba trash dirs
|
|
cron:
|
|
name: '{{ samba_cronjob_permissions.name }}'
|
|
minute: '{{ samba_cronjob_permissions.minute }}'
|
|
hour: "{{ samba_cronjob_permissions.hour | default('*') }}"
|
|
day: "{{ samba_cronjob_permissions.day | default('*') }}"
|
|
month: "{{ samba_cronjob_permissions.month| default('*') }}"
|
|
weekday: "{{ samba_cronjob_permissions.weekday| default('*') }}"
|
|
user: "{{ samba_cronjob_permissions.user | default('root') }}"
|
|
job: "{{ samba_cronjob_permissions.job }}"
|
|
when:
|
|
- "groups['samba_server']|string is search(inventory_hostname)"
|
|
- clean_samba_trash_dirs.found
|
|
|
|
|
|
# ---
|
|
# Samba clients
|
|
# ---
|
|
|
|
- name: (samba-install.yml) Ensure samba packages clients are installed.
|
|
package:
|
|
pkg: "{{ apt_install_client_samba }}"
|
|
state: present
|
|
when:
|
|
- "groups['nis_client']|string is search(inventory_hostname)"
|
|
- ansible_distribution == "Ubuntu"
|
|
tags:
|
|
- samba-client
|
|
|