smb_server.yml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. setype: samba_etc_t
  59. notify: reload smb
  60. - name: the smb service is started and enabled
  61. service:
  62. name: smb
  63. state: started
  64. enabled: yes
  65. - name: the samba firewall service is opened
  66. firewalld:
  67. service: samba
  68. state: enabled
  69. immediate: yes
  70. permanent: yes
  71. handlers:
  72. - name: reload smb
  73. service:
  74. name: smb
  75. state: reloaded