smb_server.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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: #FIXME: install the required package for a Samba server
  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. #FIXME: create the /srv/managers directory as follows:
  38. # Directory ownership: sambamount
  39. # Directory group ownership: managers
  40. # Owner access: read
  41. # Group access: read/write
  42. # Other users access: none
  43. # All contents created in the directory must automatically
  44. # belong to the managers group.
  45. # Set the correct SELinux context type.
  46. path: #FIXME#
  47. owner: #FIXME#
  48. group: #FIXME#
  49. mode: #FIXME#
  50. state: directory
  51. setype: #FIXME#
  52. - name: the directory is shared
  53. template:
  54. #FIXME: edit templates/smb.conf.j2 to declare the /srv/managers
  55. # directory as an SMB share as follows:
  56. # Work group: MANAGERGROUP
  57. # SMB minimum protocol version: 3
  58. # Traffic encryption: Always required
  59. # Share name: managerdata
  60. # Access allowed to: sambamount and the
  61. # members of the managers group
  62. # Read/write access: Members of the managers group
  63. # For your convenience, the default Samba configuration file is
  64. # available under the templates/ directory but must be updated
  65. # according to the preceding requirements.
  66. src: templates/smb.conf.j2
  67. dest: /etc/samba/smb.conf
  68. owner: root
  69. group: root
  70. mode: '0644'
  71. setype: samba_etc_t
  72. notify: reload smb
  73. - name: the SMB service is started and enabled
  74. service:
  75. name: #FIXME: the service must be started and enabled
  76. state: started
  77. enabled: yes
  78. - name: the firewall is opened for SMB
  79. firewalld:
  80. service: #FIXME: configure the firewall to allow SMB traffic
  81. state: enabled
  82. immediate: yes
  83. permanent: yes
  84. handlers:
  85. - name: reload smb
  86. service:
  87. name: #FIXME: the service must be reloaded
  88. state: reloaded