101 lines
2.4 KiB
YAML
101 lines
2.4 KiB
YAML
# File: roles/samba/tasks/main.yml
|
|
---
|
|
|
|
- include_vars: "{{ item }}"
|
|
with_first_found:
|
|
- "os_{{ ansible_distribution }}.yml"
|
|
- "os_{{ ansible_os_family }}.yml"
|
|
|
|
- name: Install Samba packages
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
with_items: "{{ samba_packages }}"
|
|
tags: samba
|
|
|
|
- name: Install SELinux package
|
|
package:
|
|
name: "{{ item }}"
|
|
state: present
|
|
with_items: "{{ samba_selinux_packages }}"
|
|
when: ansible_selinux
|
|
|
|
- name: Make sure SELinux boolean settings are correct
|
|
seboolean:
|
|
name: "{{ item }}"
|
|
state: yes
|
|
persistent: yes
|
|
with_items: "{{ samba_selinux_booleans }}"
|
|
when: ansible_selinux
|
|
|
|
- name: Create Samba shares root directory
|
|
file:
|
|
state: directory
|
|
path: "{{ samba_shares_root }}"
|
|
owner: root
|
|
group: root
|
|
mode: '0755'
|
|
when: samba_shares
|
|
tags: samba
|
|
|
|
- name: Create share directories
|
|
with_items: "{{ samba_shares }}"
|
|
file:
|
|
state: directory
|
|
path: "{{ item.path|default([samba_shares_root,item.name]|join('/')) }}"
|
|
owner: root
|
|
group: "{{ item.group|default('users') }}"
|
|
mode: "{{ item.directory_mode|default('0775') }}"
|
|
setype: "{{ item.setype|default('samba_share_t') }}"
|
|
when: samba_shares
|
|
tags: samba
|
|
|
|
- name: Check if webserver document root exists
|
|
when: samba_create_varwww_symlinks
|
|
stat:
|
|
path: "{{ samba_www_documentroot }}"
|
|
register: documentroot
|
|
tags: samba
|
|
|
|
- name: Create link to shares in webserver document root
|
|
when: documentroot.stat.isdir is defined and documentroot.stat.isdir == true
|
|
file:
|
|
state: link
|
|
path: "{{ samba_www_documentroot }}/{{ item.name }}"
|
|
src: "{{ item.path|default([samba_shares_root,item.name]|join('/')) }}"
|
|
with_items: "{{ samba_shares }}"
|
|
tags: samba
|
|
|
|
- name: Samba configuration
|
|
template:
|
|
dest: /etc/samba/smb.conf
|
|
src: smb.conf.j2
|
|
validate: 'testparm -s %s'
|
|
notify:
|
|
- Restart Samba
|
|
- Restart WinBind
|
|
tags: samba
|
|
|
|
- name: Start Samba service
|
|
service:
|
|
name: "{{ samba_service }}"
|
|
state: started
|
|
enabled: yes
|
|
tags: samba
|
|
|
|
- name: Start WindBind service
|
|
service:
|
|
name: "{{ winbind_service }}"
|
|
state: started
|
|
enabled: yes
|
|
tags: samba
|
|
|
|
- name: Create Samba users if they don't exist yet
|
|
shell: >
|
|
(pdbedit -L | grep {{ item.name }} 2>&1 > /dev/null) \
|
|
|| (echo {{ item.password }}; echo {{ item.password }}) \
|
|
| smbpasswd -s -a {{ item.name }}
|
|
with_items: "{{ samba_users }}"
|
|
when: samba_users
|
|
tags: samba
|