geerlingguy / arm-nas

Arm NAS configuration with ZFS.
GNU General Public License v3.0
123 stars 6 forks source link

Can't override ZFS's default share name in Ansible or via CLI #6

Closed geerlingguy closed 8 months ago

geerlingguy commented 8 months ago

It looks like I've run into a bug:

jgeerling@nas01:/etc/samba$ sudo zfs set sharesmb=name=jupiter hddpool/jupiter
cannot set property for 'hddpool/jupiter': 'sharesmb' cannot be set to invalid options

And if I try setting it in Ansible's zfs module extra properties, like sharesmb: 'name=jupiter', then I get:

TASK [Create Samba shares.] ********************************************************************************************
failed: [nas01.mmoffice.net] (item={'name': 'hddpool/jupiter', 'extra_zfs_properties': {'casesensitivity': 'mixed', 'sharesmb': 'name=jupiter'}}) => {"ansible_loop_var": "item", "changed": false, "item": {"extra_zfs_properties": {"casesensitivity": "mixed", "sharesmb": "name=jupiter"}, "name": "hddpool/jupiter"}, "msg": "cannot set property for 'hddpool/jupiter': 'sharesmb' cannot be set to invalid options\n"}

It looks like this is an issue in the Linux version of ZFS: https://github.com/openzfs/zfs/issues/1182

In Oracle's zfs SMB Share documentation, it suggests you can force a name if creating a share manually, e.g.:

# zfs create -o mountpoint=/users tank/users
# zfs share -o share.smb=on tank/users%ushare

What I might do is use Ansible's zfs module to create the dataset/filesystem, then manually run zfs share to create the share with the specified name... need to figure out how to make that idempotent though. Maybe check the output of smbclient -L localhost? That would require a password... Or dump the contents of whatever config file ZFS is setting up...

geerlingguy commented 8 months ago

lol, found this post from way back in 2013 complaining of the same issue.

Solution might just be to manage the Samba config myself, too...

geerlingguy commented 8 months ago

Can't do a manual rename, so looks like it's up to me to configure samba manually :)

jgeerling@nas01:/etc$ sudo zfs set sharesmb=on ssdpool/mercury%mercury
cannot open 'ssdpool/mercury%mercury': dataset does not exist
geerlingguy commented 8 months ago

It looks like ZFS stores its samba configs inside:

root@nas01:/var/lib/samba/usershares# cat ssdpool_mercury 
#VERSION 2
path=/ssdpool/mercury
comment=Comment: /ssdpool/mercury
usershare_acl=S-1-1-0:F
guest_ok=n
sharename=ssdpool_mercury

So I might just turn off smbshare in the ZFS properties, have Ansible manage the filesystem, then manually create a file in /var/lib/samba/usershares with the share itself...

That way I could just use creates: /var/lib/samba/usershares/[share name] for the command.

Found via https://bbs.archlinux.org/viewtopic.php?pid=1628280#p1628280

geerlingguy commented 8 months ago

Trying some automation but running into a weird issue with the formatting of the file, maybe:

root@nas01:/home/jgeerling# net usershare info --long
info_fn: file /var/lib/samba/usershares/jupiter is not a well formed usershare file.
info_fn: Error was Bad version number.
info_fn: file /var/lib/samba/usershares/mercury is not a well formed usershare file.
info_fn: Error was Bad version number.
root@nas01:/home/jgeerling# cat /var/lib/samba/usershares/mercury
# Ansible managed
#VERSION 2
path=/ssdpool/mercury
comment=Fast storage pool on SSDs.
usershare_acl=S-1-1-0:F
guest_ok=n
sharename=mercury
geerlingguy commented 8 months ago

Ah... can't have a comment in that file... I moved that {{ ansible_managed }} bit to the end of the Comment line, and now:

root@nas01:/home/jgeerling# net usershare info --long
[jupiter]
path=/hddpool/jupiter
comment=Archival storage pool on HDDs. (Ansible managed)
usershare_acl=Everyone:F,
guest_ok=n

[mercury]
path=/ssdpool/mercury
comment=Fast storage pool on SSDs. (Ansible managed)
usershare_acl=Everyone:F,
guest_ok=n

And now, it works!

jgeerling@nas01:~$ smbclient -L localhost
Password for [WORKGROUP\jgeerling]:

    Sharename       Type      Comment
    ---------       ----      -------
    print$          Disk      Printer Drivers
    IPC$            IPC       IPC Service (nas01 server (Samba, Ubuntu))
    mercury         Disk      Fast storage pool on SSDs. (Ansible managed)
    jupiter         Disk      Archival storage pool on HDDs. (Ansible managed)
SMB1 disabled -- no workgroup available

Hooray!

geerlingguy commented 8 months ago

Fixed via above commit. Yay!

tracing-home commented 8 months ago

I realize this is closed, but I since I was struggling to set my own share name the last few days. I just want to add what I came up with. I didn't want to edit/create the files usershares myself.

First the solution that OpenZFS accepts, created the unwanted sharename backpool_localmedia : zfs set sharesmb=on backpool/localMedia after that

net usershare add localMedia /backpool/localMedia "media share" martin:F guest_ok=n

This generates a second file in the usershares with the desired sharename "localMedia"

I can now mount with either sharename from another box. Maybe it helps you or others until zfs set share=name=fs1 works on OpenZFS