Showing posts with label samba. Show all posts
Showing posts with label samba. Show all posts

Tuesday, September 23, 2014

Puppet: mount a SAMBA share at boot

First, create a credentials file in your acme module:
acme\files\samba\myshare.smb.credentials
and inside put:
username=myuser
password=mypassword

I was unable to make it mount an unprotected share..... so just have it protected by username/password.

Then in your acme init.pp read a boolean

$acme_install_sambamyshare = any2bool(hiera('acme_install_sambamyshare', false)),

Create a samba.pp class (file):

# == Class: acme::samba
#
# Manages samba mounts
#
class acme::samba {
  if $acme::acme_install_sambamyshare {
    file { '/data/myshare/':
      ensure => directory,
      owner  => "soa",
      group  => 'soa',
      mode   => '0775',
    }

    file { '/etc/myshare.smb.credentials': source => 'puppet:///modules/acme/samba/myshare.smb.credentials', 
  owner => root,
      mode => '0700', } ->
    mount { 'myshare':
      name    => '/data/myshare/',
      atboot  => 'true',
      device  => '//windowshost/sharedfolder',
      ensure  => 'mounted',
      fstype  => 'cifs',
      options => "credentials=/etc/myshare.smb.credentials,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777",
      require => [Package['samba-client'], Package['cifs-utils'], File['/data/myshare/'], File['/etc/myshare.smb.credentials']],
    }
  }

}



Don't forget to declare the samba class in your init.pp!

If you do cat /etc/fstab you should see something like this:

//windowshost/sharedfolder /data/myshare/ cifs credentials=/etc/myshare.smb.credentials,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

If you want to do the same thing manually, this is the recipe:

yum install smbclient
//yum install cifs-utils for Ubuntu
/bin/mount -t cifs -o username=someuser,password=somepassword,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777 //windowshost/sharedfolder /data/myshare/

To remove a mountpoint, use umount:

umount /data/myshare/

it supports also a -f (force) option:

umount -f /data/myshare/

See also here

Monday, February 6, 2012

SAMBA mountpoints on Linux

How do I find out which SAMBA mountpounts I have on my box?

Using mount you shall find some Common Internet File System (CIFS) entries :

[soa@hqchACMESOA104 ffmw]$ mount

/dev/mapper/rootvg-rootlv on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/mapper/rootvg-tmplv on /tmp type ext3 (rw)
/dev/mapper/rootvg-optlv on /opt type ext3 (rw)
/dev/mapper/rootvg-homelv on /home type ext3 (rw)
/dev/mapper/rootvg-varlv on /var type ext3 (rw)
/dev/cciss/c0d0p1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
//acme1999.ACME.com/zdata/ER/ACMESOA/3786 on /data/ffmw/ACME1 type cifs (rw,mand,noexec,nosuid,nodev)
//chornl1999.ACME.com/zdata/ER/ACMESOA/0983 on /data/ffmw/ACME2 type cifs (rw,mand,noexec,nosuid,nodev)


[soa@hqchACMESOA104 ffmw]$ cat /etc/fstab

/dev/rootvg/rootlv / ext3 defaults 1 1
/dev/rootvg/tmplv /tmp ext3 defaults 1 2
/dev/rootvg/optlv /opt ext3 defaults 1 2
/dev/rootvg/homelv /home ext3 defaults 1 2
/dev/rootvg/varlv /var ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/rootvg/swaplv swap swap defaults 0 0
//acme1999.ACME.com/zdata/ER/ACMESOA/3786 /data/ffmw/ACME1 cifs rw,domain=ACME,username=CHAVEACMESOA,password=AVENes0a,auto,users 0 0
//emcal1999.ACME.com/zdata/ER/ACMESOA/0983 /data/ffmw/ACME2 cifs rw,domain=ACME,username=CHORNACMESOA,password=ORNNes0a,auto,users 0 0