From 61401c36051f7b097f80a22de6d6d84cc78b69ad Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 17 Dec 2024 02:21:03 +0100 Subject: add samba role --- roles/samba/README.md | 2 ++ roles/samba/defaults/main.yml | 2 ++ roles/samba/handlers/main.yml | 12 ++++++++++ roles/samba/tasks/main.yml | 49 +++++++++++++++++++++++++++++++++++++++ roles/samba/templates/smb.conf.j2 | 15 ++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 roles/samba/README.md create mode 100644 roles/samba/defaults/main.yml create mode 100644 roles/samba/handlers/main.yml create mode 100644 roles/samba/tasks/main.yml create mode 100644 roles/samba/templates/smb.conf.j2 diff --git a/roles/samba/README.md b/roles/samba/README.md new file mode 100644 index 0000000..db14c86 --- /dev/null +++ b/roles/samba/README.md @@ -0,0 +1,2 @@ +This role configures an anonymous Samba share. It doesn't support multiple +shares, authentication or anything like that. diff --git a/roles/samba/defaults/main.yml b/roles/samba/defaults/main.yml new file mode 100644 index 0000000..d032b7f --- /dev/null +++ b/roles/samba/defaults/main.yml @@ -0,0 +1,2 @@ +#samba_share_dir: +#samba_share_name: diff --git a/roles/samba/handlers/main.yml b/roles/samba/handlers/main.yml new file mode 100644 index 0000000..81dfe5e --- /dev/null +++ b/roles/samba/handlers/main.yml @@ -0,0 +1,12 @@ +- name: Collect service facts + ansible.builtin.service_facts: + listen: samba_configured + +- name: Restart Samba service + become: true + when: | + 'smbd.service' in ansible_facts.services and ansible_facts.services['smbd.service'].state == 'running' + ansible.builtin.systemd_service: + name: smbd + state: restarted + listen: samba_configured diff --git a/roles/samba/tasks/main.yml b/roles/samba/tasks/main.yml new file mode 100644 index 0000000..97aff98 --- /dev/null +++ b/roles/samba/tasks/main.yml @@ -0,0 +1,49 @@ +- name: Install Samba + become: true + ansible.builtin.package: + name: samba + state: present + +- name: Create /etc/samba + become: true + ansible.builtin.file: + path: /etc/samba + state: directory + owner: root + group: root + mode: '755' + +- name: Format smb.conf + become: true + ansible.builtin.template: + src: smb.conf.j2 + dest: /etc/samba/smb.conf + owner: root + group: root + mode: '644' + validate: '/usr/bin/testparm --suppress-prompt %s' + notify: samba_configured + +- name: Enable & start Samba + become: true + ansible.builtin.systemd_service: + name: smbd + enabled: true + state: started + +- name: Restart Samba service if necessary + ansible.builtin.meta: flush_handlers + +# Enable network discovery on Windows. +- name: Install wsdd + become: true + ansible.builtin.package: + name: wsdd + state: present + +- name: Enable & start wsdd + become: true + ansible.builtin.systemd_service: + name: wsdd + enabled: true + state: started diff --git a/roles/samba/templates/smb.conf.j2 b/roles/samba/templates/smb.conf.j2 new file mode 100644 index 0000000..00ef87b --- /dev/null +++ b/roles/samba/templates/smb.conf.j2 @@ -0,0 +1,15 @@ +{{ ansible_managed | comment }} + +# https://wiki.samba.org/index.php/Setting_up_Samba_as_a_Standalone_Server#Creating_a_Basic_guest_only_smb.conf_File + +[global] + logging = syslog + map to guest = Bad user + server role = standalone server + auto services = {{ samba_share_name }} + +[{{ samba_share_name }}] + path = {{ samba_share_dir }} + read only = no + guest ok = yes + guest only = yes -- cgit v1.2.3