# {{ ansible_managed }}

# -----------------------------------------------------
# - Settings for script set_permissions_samba_shares.sh
# -----------------------------------------------------

# - dir_permissions
# -
# - Recursive set Permissions (group and file- and directory-mode)
# -
# - Multiple options are possible. Use semicolon separated list.
# -
# - Usage:
# -   dir_permissions="<directory>:<group>:<file-mod>:<dir-mod>;[<directory>:<group>:<file-mod>:<dir-mod>];[.."
# -
# - Example:
# -    dir_permissions="/data/samba/transfer:buero:664:2775;/data/samba/verwaltung:intern:660:2770"
# -
#dir_permissions=""

{%- set count = namespace(samba_shares=0) %}

{%- for item in samba_shares | default([]) %}
{%    set count.samba_shares = count.samba_shares + 1 %}
{% endfor %}

{% if count.samba_shares > 0 %}
dir_permissions="
{%    for item in samba_shares | default([]) %}
{%       if item.file_create_mask is defined and item.file_create_mask|length > 0 
            and item.dir_create_mask is defined and  item.dir_create_mask|length > 0 
            and item.group_write_list is defined and item.group_write_list|length > 0 %}
   {{ item.path }}:{{ item.group_write_list | default('root', true) }}:{{ item.file_create_mask|string | default('660', true) }}:{{ item.dir_create_mask | default('2770', true) }};
{%    endif  %}
{%    endfor %}
"
{% endif %}
