We have plenty of linux server that will mount a few linux file server by NFS or SMB using /etc/fstab
But manually changing each server's /etc/fstab
is very tedious.
Is there any way to edit multiple linux server's /etc/fstab
simultaneously?
We have plenty of linux server that will mount a few linux file server by NFS or SMB using /etc/fstab
But manually changing each server's /etc/fstab
is very tedious.
Is there any way to edit multiple linux server's /etc/fstab
simultaneously?
Long term, this is the sort of tasks that configuration management tools (e.g., puppet
, chef
, ansible
) are made for.
For a short term solution, I'd use something like func
or fabric
to push out your fstab
file. Going to run through an example of using fabric
since that's the one I'm most familiar with.
Installation depends on your distro. One of these is likely to work:
$ sudo pip install fabric
$ sudo easy_install fabric
$ sudo apt-get install fabric
Then, you'll also need to distribute ssh keys. It's simple:
$ ssh-keygen
$ ssh-copy-id host2
$ ssh-copy-id host3
Now, you'll need to create a fab
file (pretty much a Python
script). For example, copy_fstab.fab
would look something like this:
from fabric.operations import put
from fabric.operations import sudo
def copy_fstab():
# Copy local fstab over
put('/etc/fstab', '/etc/fstab', use_sudo=True)
# Run mount -a
sudo('mount -a')
Finally, you run the fab file:
$ fab -H host2,host3 copy_fstab
Hope this helps!
Using a mass deployment tool like automateit, salt, puppet, ansible, etc. you could run a script (in puppet use exec) or a cronjob like below to use mount to run a mass deployed fstab:
mount -a --fstab pathtofile
And my old answer (if your mount is too old to have --fstab / -T): in such a mass deployment tool, you could do some terrible hackery to emulate an /etc/fstab.d behavior (since /etc/fstab.d is not yet supported, and those directories make deployment tools very useful).
Move fstab to /etc/fstab.d/01main
Deploy your fstab line in a file /etc/fstab.d/02nfsstuff
Merge them (here the number order is important):
cat /etc/fstab.d/* > /etc/fstab
Make a horrible hackjob cronjob in /etc/cron.d/nfsstuff
0 * * * * root cat /etc/fstab.d/* > /etc/fstab ; mount -a
I hope you find a proper solution, but until then, maybe this is useful.
I agree with Peter that using a deployment tool is the neatest solution. However I disagree that mouning stuff from cron is ever a good idea!
If the deployment tool is too much of a leap, I'd go with a late init/systemd script (which might fetch the definitions from a central respository) and mount the filesystems.
Assuming I have an admin account on each server available via SSH with public-key auth, I would simply remotely run sed or other text editing tool using this SSH account, in a bash loop.