smb_server.yml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ---
  2. - name: Share a directory with SMB
  3. hosts: serverd.lab.example.com
  4. become: true
  5. vars_files:
  6. - smb_vars.yml
  7. tasks:
  8. - name: the samba package is installed
  9. yum:
  10. name: samba
  11. state: present
  12. # Creating the Linux and Samba user for the multiuser mount.
  13. # That user is only used to mount the share.
  14. - name: the Linux user for Samba mount exists
  15. user:
  16. name: "{{ samba_usermount }}"
  17. shell: /sbin/nologin
  18. create_home: no
  19. system: yes
  20. - name: the Samba user for Samba mount exists
  21. command: smbpasswd -s -a {{ samba_usermount }}
  22. args:
  23. stdin: "{{ samba_passmount }}\n{{ samba_passmount }}"
  24. # Group and users with write access to the share
  25. - name: the Linux group exists
  26. group:
  27. name: "{{ allowed_group }}"
  28. system: yes
  29. - name: the Linux users exist for Samba users
  30. user:
  31. name: "{{ item['name'] }}"
  32. shell: /sbin/nologin
  33. groups:
  34. - "{{ allowed_group }}"
  35. loop: "{{ samba_users }}"
  36. no_log: true
  37. - name: the Samba users exist
  38. command: smbpasswd -s -a {{ item['name'] }}
  39. args:
  40. stdin: "{{ item['password'] }}\n{{ item['password'] }}"
  41. loop: "{{ samba_users }}"
  42. no_log: true
  43. - name: the directory exists
  44. file:
  45. path: "{{ shared_dir }}"
  46. owner: root
  47. group: "{{ allowed_group }}"
  48. mode: '2775'
  49. state: directory
  50. setype: samba_share_t
  51. - name: the directory is shared
  52. template:
  53. src: templates/smb.conf.j2
  54. dest: /etc/samba/smb.conf
  55. owner: root
  56. group: root
  57. mode: 0644
  58. notify: reload smb
  59. - name: the smb service is started and enabled
  60. service:
  61. name: smb
  62. state: started
  63. enabled: yes
  64. - name: the samba firewall service is opened
  65. firewalld:
  66. service: samba
  67. state: enabled
  68. permanent: yes
  69. immediate: yes
  70. handlers:
  71. - name: reload smb
  72. service:
  73. name: smb
  74. state: reloaded