- name: Install Samba
  apt:
    pkg:
      - samba

- name: Samba public group
  group:
    name: smb
    system: true

- name: Samba public user
  user:
    name: smb
    group: smb
    shell: /usr/sbin/nologin
    home: /var/empty
    system: true
    create_home: false

- name: Samba config
  template:
    dest: /etc/samba/smb.conf
    src: smb.conf.j2
    validate: testparm -s %s
  register: samba_config

- name: Reload Samba
  systemd:
    name: '{{item}}'
    state: '{{"restarted" if samba_config.changed else "started"}}'
    enabled: true
  loop:
    - smbd
    - nmbd
