- name: "Create smb user: {{ smbuser }}"
  user:
    name: "{{ smbuser }}"
    shell: /sbin/nologin
    password: "{{ smbpassword }}"

- name: "Create public folder: {{ shared_dir }}"    # /library/public
  file:
    path: "{{ shared_dir }}"
    owner: "{{ smbuser }}"
    group: "{{ smbuser }}"
    mode: '0777'
    state: directory

# Install and configure samba server (requires ports 137, 138, 139, 445 open).
- name: "Install 4 packages: samba, samba-client, samba-common, cifs-client"
  package:
    name:
      - samba
      - samba-client
      - samba-common
      - cifs-utils
    state: present

- name: Install /etc/samba/smb.conf from template
  template:
    src: smb.conf.j2
    dest: /etc/samba/smb.conf


# RECORD Samba AS INSTALLED

- name: "Set 'samba_installed: True'"
  set_fact:
    samba_installed: True

- name: "Add 'samba_installed: True' to {{ iiab_state_file }}"
  lineinfile:
    path: "{{ iiab_state_file }}"    # /etc/iiab/iiab_state.yml
    regexp: '^samba_installed'
    line: 'samba_installed: True'
