smb_server.yml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ---
  2. - name: Share a directory with SMB
  3. hosts: serverc.lab.example.com
  4. become: true
  5. vars_files:
  6. - smb_vars.yml
  7. tasks:
  8. - name: the package for a Samba server is installed
  9. yum:
  10. name: samba
  11. state: present
  12. - name: the Linux group for Samba users exists
  13. group:
  14. name: "{{ allowed_group }}"
  15. - name: the Linux user for Samba exists
  16. user:
  17. name: "{{ samba_user }}"
  18. password: "{{ samba_user_password | password_hash('sha512', 'secretsalt') }}"
  19. groups:
  20. - "{{ allowed_group }}"
  21. - name: the Linux user is in Samba database
  22. command: smbpasswd -s -a {{ samba_user }}
  23. args:
  24. stdin: "{{ samba_user_password }}\n{{ samba_user_password }}"
  25. - name: the Linux user for Samba mount exists
  26. user:
  27. name: "{{ samba_usermount }}"
  28. shell: /sbin/nologin
  29. create_home: no
  30. system: yes
  31. - name: the Samba user for Samba mount exists
  32. command: smbpasswd -s -a {{ samba_usermount }}
  33. args:
  34. stdin: "{{ samba_passmount }}\n{{ samba_passmount }}"
  35. - name: the directory exists
  36. file:
  37. path: "{{ shared_dir }}"
  38. owner: "{{ samba_usermount }}"
  39. group: "{{ allowed_group }}"
  40. mode: '2570'
  41. state: directory
  42. setype: samba_share_t
  43. - name: the directory is shared
  44. template:
  45. src: templates/smb.conf.j2
  46. dest: /etc/samba/smb.conf
  47. owner: root
  48. group: root
  49. mode: '0644'
  50. setype: samba_etc_t
  51. notify: reload smb
  52. - name: the SMB service is started and enabled
  53. service:
  54. name: smb
  55. state: started
  56. enabled: yes
  57. - name: the firewall is opened for SMB
  58. firewalld:
  59. service: samba
  60. state: enabled
  61. immediate: yes
  62. permanent: yes
  63. handlers:
  64. - name: reload smb
  65. service:
  66. name: smb
  67. state: reloaded