Similar to ansible
command but allows you to use any command that will work in your shell. Not tied to specific
configuration management tooling, just SSH and your default shell on remote systems. Just works. I <3 it :)
Runs commands across potentially many machines. Allows you to organize your servers/VMs/instances into groups very easily.
Most OSes just have a package for it in their package management system. Doesn't rely on Python or Ruby or whatever. e.g.
# On NixOS/Nix
nix-env -i pdsh
# On Ubuntu
sudo apt-get install dsh
# On CentOS/Fedora/RHEL/YUM-based repos
sudo yum install dsh
# Using Homebrew on OS X
brew install dsh
So there is usually a directory where you can define your host groups in plain text files. It's that simple.
On most *NIX systems it is /etc/dsh
. *NIX conventions FTW. Nothing fancy again.
Most user accounts on a *NIX system will add host group files to their $HOME/.dsh/group
directory.
$ tree /etc/dsh/ | head -15
/etc/dsh/
├── dsh.conf
├── group
│ ├── all -> ../machines.list
│ ├── prod.admin
│ ├── prod.api
│ ├── prod.cache
│ ├── prod.proxy
│ ├── prod.webapp
│ ├── prod.webcache
...
│ ├── profiling.admin
│ ├── profiling.api
│ ├── profiling.cache
│ ├── profiling.proxy
│ ├── profiling.webapp
│ ├── profiling.webcache
...
│ ├── staging.admin
│ ├── staging.api
│ ├── staging.cache
│ ├── staging.proxy
│ ├── staging.webapp
│ ├── staging.webcache
...
│ └── api.all
│ └── cache.all
│ └── proxy.all
│ └── webcache.all
│ └── webapp.all
└── machines.list
$ cat /etc/dsh/group/prod.webapp
webapp001.appname.com
webapp002.appname.com
webapp003.appname.com
webapp004.appname.com
webapp005.appname.com
webapp006.appname.com
webapp007.appname.com
...
webapp123.appname.com
Let's do something.
pdsh -R ssh -M -g webcache.all 'sudo service varnish restart'
pdsh -R ssh -cM -F 4 -g webapp.prod 'pgrep -f my_awesome_app'
pdsh -R ssh -m webapp001.appname.com -m webcache003.appname.com -m proxy005.appname.com 'sudo reboot'
pdsh -R ssh -g staging.webapp -g staging.admin 'sudo service nginx reload'
pdsh -R ssh -cF 5 -g all 'ss | awk '{ print $4 }' | sort | uniq'
This is an example of the global dsh.conf
file.
$ cat /etc/dsh/dsh.conf
verbose = 0
remoteshell = ssh
showmachinenames = 0
waitshell = 1
remoteshellopt=-q
Pretty simple. Check the man pages for more information.
I have installed
apt-get install pdsh dsh
on ubuntu 20.04 but look like it doesn't support dshgroup. look like they removed support of dsh in newer release