aboutsummaryrefslogtreecommitdiff
blob: 80950dcb80be4c5eeaf886de747a5bf465cda7ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
- name: Install Samba
  apt:
    name:
      - samba
      - smbclient
      - cifs-utils
    update_cache: true

- name: Disable Samba NetBIOS server nmbd
  systemd:
    name: nmbd
    state: stopped
    enabled: false

- name: render samba config file
  template:
    src: smb.conf.j2
    dest: "/etc/samba/smb.conf"
    mode: 0644

# https://stackoverflow.com/questions/44762488/non-interactive-samba-user-creation-via-ansible
- name: shell - create samba users
  shell: >
    set -e -o pipefail
    && (pdbedit --user={{ item.username }} 2>&1 > /dev/null)
    || (echo '{{ item.password }}'; echo '{{ item.password }}')
    | smbpasswd -s -a {{ item.username }}
  args:
    executable: /bin/bash
  register: samba_create_users
  changed_when: "'Added user' in samba_create_users.stdout"
  loop: "{{ samba_users }}"
  no_log: true

- name: shell - set samba passwords correctly
  shell: >
    set -e -o pipefail
    && (smbclient -U {{ item.username }}%{{ item.password }} -L 127.0.0.1 2>&1 > /dev/null)
    || (echo '{{ item.password }}'; echo '{{ item.password }}')
    | smbpasswd {{ item.username }}
  args:
    executable: /bin/bash
  register: samba_verify_users
  changed_when: "'New SMB password' in samba_verify_users.stdout"
  loop: "{{ samba_users }}"
  no_log: true

- name: Restart SMB service
  systemd:
    name: smbd
    state: restarted
    enabled: true
    daemon_reload: true
Powered by cgit v1.2.3 (git 2.41.0)