update..
This commit is contained in:
@ -226,6 +226,15 @@
|
||||
tags:
|
||||
- apt-webserver-pkgs
|
||||
|
||||
- name: (apt.yml) Install samba related packages
|
||||
package:
|
||||
pkg: '{{ apt_install_server_samba }}'
|
||||
state: present
|
||||
when:
|
||||
- "groups['samba_server']|string is search(inventory_hostname)"
|
||||
tags:
|
||||
- samba-server
|
||||
|
||||
- name: (apt.yml) Install extra packages
|
||||
apt:
|
||||
name: "{{ apt_extra_pkgs }}"
|
||||
|
@ -4,7 +4,7 @@
|
||||
cron:
|
||||
name: '{{ item.name }}'
|
||||
env: 'yes'
|
||||
user: '{{ item.user | default(omit) }}'
|
||||
user: '{{ item.user | default("root", true) }}'
|
||||
job: '{{ item.job }}'
|
||||
insertafter: '{{ item.insertafter | default(omit) }}'
|
||||
loop: "{{ cron_env_entries }}"
|
||||
@ -19,7 +19,7 @@
|
||||
cron:
|
||||
name: '{{ item.name }}'
|
||||
special_time: '{{ item.special_time }}'
|
||||
user: '{{ item.user | default(omit) }}'
|
||||
user: '{{ item.user | default("root", true) }}'
|
||||
job: '{{ item.job }}'
|
||||
state: present
|
||||
loop: "{{ cron_user_special_time_entries }}"
|
||||
@ -34,7 +34,7 @@
|
||||
cron:
|
||||
name: '{{ item.name }}'
|
||||
minute: '{{ item.minute | default(omit) }}'
|
||||
hour: '{{ item.hour | default(omit) }}'
|
||||
hour: '{{ item.hour | default("root", true) }}'
|
||||
day: '{{ day | default(omit) }}'
|
||||
weekday: '{{ item.weekday | default(omit) }}'
|
||||
month: '{{ item.month | default(omit) }}'
|
||||
|
@ -148,6 +148,40 @@
|
||||
tags:
|
||||
- config-files-mailsystem
|
||||
|
||||
# tags supported inside samba-user.yml:
|
||||
#
|
||||
# samba-server
|
||||
# samba-user
|
||||
# system-user
|
||||
#
|
||||
- import_tasks: samba-user.yml
|
||||
when: inventory_hostname in groups['samba_server']
|
||||
tags:
|
||||
- samba-server
|
||||
|
||||
# tags supported inside samba-config-server.yml:
|
||||
#
|
||||
# samba-server
|
||||
# samba-shares
|
||||
# samba-server
|
||||
# samba-cron
|
||||
#
|
||||
- import_tasks: samba-config-server.yml
|
||||
when: inventory_hostname in groups['samba_server']
|
||||
tags:
|
||||
- samba-server
|
||||
|
||||
# tags supported inside samba-remove-user.yml:
|
||||
#
|
||||
# samba-server
|
||||
# samba-user
|
||||
# system-user
|
||||
#
|
||||
- import_tasks: samba-remove-user.yml
|
||||
when: inventory_hostname in groups['samba_server']
|
||||
tags:
|
||||
- samba-server
|
||||
|
||||
# tags supportetd inside caching-nameserver.yml
|
||||
#
|
||||
# apt-caching-nameserver
|
||||
|
181
roles/common/tasks/samba-config-server.yml
Normal file
181
roles/common/tasks/samba-config-server.yml
Normal file
@ -0,0 +1,181 @@
|
||||
---
|
||||
|
||||
# ---
|
||||
# Samba Server
|
||||
# ---
|
||||
|
||||
- name: (samba-config-server.yml) Ensure samba share directories exists
|
||||
file:
|
||||
path: "{{ item.path }}"
|
||||
owner: "root"
|
||||
group: "{{ item.group_write_list | default('root', true) }}"
|
||||
mode: '2770'
|
||||
state: directory
|
||||
recurse: yes
|
||||
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-config-server.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-config-server.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-config-server.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)"
|
||||
- samba_user is defined and samba_user|length > 0
|
||||
- samba_shares is defined and samba_shares|length > 0
|
||||
notify:
|
||||
- Restart smbd
|
||||
- Restart nmbd
|
||||
tags:
|
||||
- samba-server
|
||||
|
||||
|
||||
- name: (samba-config-server.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-config-server.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)"
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-cron
|
||||
|
||||
- name: (samba-config-server.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
|
||||
- samba-cron
|
||||
|
||||
|
||||
- name: (samba-config-server.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)"
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-cron
|
||||
|
||||
|
||||
- name: (samba-config-server.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_exists.stat.exists|bool and clean_samba_trash_dirs.found
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-cron
|
||||
|
||||
|
||||
# ---
|
||||
# Cronjob for setting permissions on samba shares
|
||||
# ---
|
||||
|
||||
- name: (samba-config-server.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)"
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-cron
|
||||
|
||||
- name: (samba-config-server.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
|
||||
- samba-cron
|
||||
|
||||
|
||||
- name: (samba-config-server.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
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-cron
|
||||
|
58
roles/common/tasks/samba-remove-user.yml
Normal file
58
roles/common/tasks/samba-remove-user.yml
Normal file
@ -0,0 +1,58 @@
|
||||
---
|
||||
|
||||
# ---
|
||||
# - Remove unwanted users
|
||||
# ---
|
||||
|
||||
|
||||
- name: (samba-remove-user.yml) Check if samba user exists for removable system user
|
||||
shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep '{{ item.name }}'
|
||||
register: samba_remove_system_users_present
|
||||
changed_when: "samba_remove_system_users_present.rc == 0"
|
||||
failed_when: "samba_remove_system_users_present.rc > 1"
|
||||
with_items:
|
||||
- "{{ remove_samba_users }}"
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
tags:
|
||||
- system-user
|
||||
- samba-user
|
||||
|
||||
|
||||
- name: (samba-remove-user.yml) Remove (old) system users from samba
|
||||
shell: >
|
||||
smbpasswd -s -x {{ item.item.name }}
|
||||
with_items:
|
||||
- "{{ samba_remove_system_users_present.results }}"
|
||||
loop_control:
|
||||
label: '{{ item.item.name }}'
|
||||
when:
|
||||
- item.changed
|
||||
tags:
|
||||
- system-user
|
||||
- samba-user
|
||||
|
||||
- name: (samba-remove-user.yml) Remove users from system
|
||||
user:
|
||||
name: '{{ item.name }}'
|
||||
state: absent
|
||||
with_items:
|
||||
- "{{ remove_samba_users }}"
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
tags:
|
||||
- system-user
|
||||
- samba-user
|
||||
|
||||
- name: (samba-remove-user.yml) Remove home directory from deleted users
|
||||
file:
|
||||
path: "{{ base_home | default('/home', true) }}/{{ item.name }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- "{{ remove_samba_users }}"
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
tags:
|
||||
- system-user
|
||||
- samba-user
|
||||
|
75
roles/common/tasks/samba-user.yml
Normal file
75
roles/common/tasks/samba-user.yml
Normal file
@ -0,0 +1,75 @@
|
||||
---
|
||||
|
||||
# ---
|
||||
# - default user/groups
|
||||
# ---
|
||||
|
||||
# To be precise, samba groups are system groups.
|
||||
#
|
||||
- name: (samba-user.yml) Ensure samba groups exists
|
||||
group:
|
||||
name: '{{ item.name }}'
|
||||
state: present
|
||||
gid: '{{ item.group_id | default(omit) }}'
|
||||
loop: "{{ samba_groups }}"
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
when: item.group_id is defined
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-group
|
||||
- system-group
|
||||
|
||||
# get all user of the system
|
||||
#
|
||||
# Note:
|
||||
# the result ist avalable in variable getent_passwd
|
||||
#
|
||||
- name: (samba_user.yml) Get database of (system) users
|
||||
getent:
|
||||
database: passwd
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-user
|
||||
- system-user
|
||||
|
||||
|
||||
# Samba users mut be also system users
|
||||
#
|
||||
- name: (samba_user.yml) Add (system) users if not yet exists..
|
||||
shell: "/root/bin/admin-stuff/add_new_user.sh {{ item.name }} '{{ item.password }}'"
|
||||
loop: "{{ samba_user }}"
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
when:
|
||||
- item.name not in getent_passwd
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-user
|
||||
- system-user
|
||||
|
||||
|
||||
- name: (samba-user.yml) Check if samba user exists
|
||||
shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep '{{ item.name }}'
|
||||
register: samba_user_present
|
||||
changed_when: "samba_user_present.rc == 1"
|
||||
failed_when: "samba_user_present.rc > 1"
|
||||
loop: "{{ samba_user }}"
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-user
|
||||
|
||||
- name: (samba-user.yml) Add user to samba (with system users password)
|
||||
shell: >
|
||||
(echo '{{ item.item.password }}'; echo '{{ item.item.password }}')
|
||||
| smbpasswd -s -a {{ item.item.name }}
|
||||
loop: "{{ samba_user_present.results }}"
|
||||
when: item.changed
|
||||
loop_control:
|
||||
label: '{{ item.item.name }}'
|
||||
tags:
|
||||
- samba-server
|
||||
- samba-user
|
||||
|
Reference in New Issue
Block a user