diff --git a/defaults/main.yml b/defaults/main.yml index e9e0e3d..d18c04d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,3 +9,4 @@ samba_passdb_backend: 'tdbsam' samba_map_to_guest: 'bad user' samba_load_printers: 'no' samba_load_homes: 'no' +samba_shares_root: '/srv/shares' diff --git a/tasks/main.yml b/tasks/main.yml index d98a0c7..9e887ab 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,10 +26,10 @@ with_items: samba_shares file: state: directory - path: "{{ item.path }}" + path: "{{ samba_shares_root}}/{{ item.name }}" owner: root - group: "{{ item.force_group }}" - mode: "{{ item.directory_mode }}" + group: "{{ item.force_group|default('users') }}" + mode: "{{ item.directory_mode|default('0775') }}" setype: "{{ item.setype|default('samba_share_t') }}" when: samba_shares is defined tags: samba @@ -45,7 +45,7 @@ file: state: link path: "/var/www/html/{{ item.name }}" - src: "{{ item.path }}" + src: "{{ samba_shares_root }}/{{ item.name }}" with_items: samba_shares tags: samba diff --git a/templates/smb.conf.j2 b/templates/smb.conf.j2 index 429e669..f79b821 100644 --- a/templates/smb.conf.j2 +++ b/templates/smb.conf.j2 @@ -48,17 +48,23 @@ {% if samba_shares is defined %} {% for share in samba_shares %} [{{ share.name }}] - comment = {{ share.comment }} - path = {{ share.path }} - public = {{ share.public }} - write list = {{ share.write_list }} + {% if share.comment is defined %} + comment = {{ share.comment }} + {% endif %} + path = {{ samba_shares_root }}/{{ share.name }} + public = {{ share.public|default('no') }} + {% if share.write_list is defined %} + write list = {{ share.write_list }} + {% endif %} - force group = +{{ share.force_group }} - create mask = {{ share.create_mask }} - create mode = {{ share.create_mode }} - force create mode = {{ share.force_create_mode }} - directory mask = {{ share.directory_mask }} - directory mode = {{ share.directory_mode }} - force directory mode = {{ share.force_directory_mode }} + {% if share.force_group is defined %} + force group = {{ share.force_group }} + {% endif %} + create mask = {{ share.create_mask|default('0664') }} + create mode = {{ share.create_mode|default('0664') }} + force create mode = {{ share.force_create_mode|default('0664') }} + directory mask = {{ share.directory_mask|default('0775') }} + directory mode = {{ share.directory_mode|default('0775') }} + force directory mode = {{ share.force_directory_mode|default('0775') }} {% endfor %} {% endif%}